Flash 随机生成多个显示元件的ActionScript代码

学习flash的练习,随机生成多个sprite显示元件,纯actionscript3.0代码。
Sprite显示元件颜色随机,大小随机 

 



代码如下:

public function testCreateSprite():void
{
for (var i:int = 0;i < 99; i++ )
{
var s:Sprite = new Sprite;
s.name = "hiname_" + i;
var color:int = Math.floor(Math.random() * 0xFFFFFF); //生成随机颜色
var size:int = Math.floor(Math.random() * 35); //生成随机大小
s.graphics.beginFill(color);
s.graphics.drawCircle(Math.random() * 700 +10, Math.random() * 600 +10, size);
s.graphics.endFill();
this.addChild(s);

s.addEventListener(MouseEvent.CLICK, clickHandler);
//s.addEventListener(MouseEvent.MOUSE_OVER, overHandler);
}
}

private function clickHandler(event:MouseEvent):void
{
trace("You click : " + event.target.name + "_typeof:" + typeof event.target.name );

this.removeChild(DisplayObject(event.target));

//var n:int = this.stage.numChildren;
//for (var i:int = 0; i < n; i++ ) {
//this.stage.removeChildAt(i);
//}

//var myTimer:MyTimer = MyTimer.getInstance();
//myTimer.registerTimer(event.target.name, 1, 20, movetoRight,event.target.name);
}


 

原文地址:https://www.cnblogs.com/didi/p/2254523.html