AS3.0复制生成多个MC(FLASH CS3.0版)

今天被别人问到如题所述的问题,想了一下复制到是很简单,但是管理和判断点击的生成MC却有些麻烦,不过有个偷懒但是很好用的做法,那就是在MC内部覆盖一个点击范围大小的按钮,如此一来就好判断了.

代码到是很简单如下:

for(var i:int = 0;i<5;i++){
    this["btnMC"+i] = new btn();
    this["btnMC"+i].name ="btn"+i;
    this["btnMC"+i].btnText.text = "btn"+i;
    this["btnMC"+i].x = 30;
    this["btnMC"+i].y = 25*i;
    this["btnMC"+i].addEventListener(MouseEvent.CLICK,btnHandle);
    addChild(this["btnMC"+i]);
    }
function btnHandle(event:MouseEvent):void{
     trace(event.target.parent.name)
    }

点击下载源文件

Advertisements

发表评论

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 / 更改 )

Twitter picture

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

Facebook photo

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

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: