Second Class



This is improved version of previous post this is more reusable then previous post.
package  
{
	import flash.display.Graphics;
	import flash.display.MovieClip;
	/**
	 * ...
	 * @author Jeet Chauhan
	 */
	public class BallWithParameter extends MovieClip
	{
		private var color:uint;
		private var radius:Number;
		
		public function BallWithParameter(radius:Number = 10,color:uint=0xffff00) 
		{
			this.color = color;
			this.radius = radius;
			draw()
		}
		
		private function draw():void
		{
			var g:Graphics = graphics;
			g.beginFill(color, 1);
			g.drawCircle(0, 0, radius);
		}
		
	}

}

This class initilize random color and radius ball use it as a document class

package  
{
	import flash.display.MovieClip;
	
	/**
	 * ...
	 * @author Jeet Chauhan
	 */
	public class MultipleBall extends MovieClip
	{
		
		public function MultipleBall() 
		{
			draw()
		}
		
		private function draw():void
		{
			var ball:BallWithParameter = new BallWithParameter(Math.random() * 5 + 5, Math.random() * 0xffffff);
			ball.x = Math.random() * stage.stageWidth;
			ball.y = Math.random() * stage.stageHeight;
			addChild(ball);
		}
		
	}

}

this will create multiple circles

package  
{
	import flash.display.MovieClip;
	
	/**
	 * ...
	 * @author Jeet Chauhan
	 */
	public class MultipleBall extends MovieClip
	{
		
		public function MultipleBall() 
		{
			draw()
		}
		
		private function draw():void
		{
			for (var i:int = 0; i < 100; i++) 
			{
				var ball:BallWithParameter = new BallWithParameter(Math.random() * 5 + 5, Math.random() * 0xffffff);
				ball.x = Math.random() * stage.stageWidth;
				ball.y = Math.random() * stage.stageHeight;
				addChild(ball);
			}
			
		}
		
	}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s