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);
}
}
}
}
Like this:
Like Loading...
Related