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/archive/2011/11/18/2254523.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值