小编oni*_*io9的帖子

使用不同的参数在循环中创建匿名函数

我想制作循环按钮组,并向它们添加一些事件,但匿名函数是相同的.我写了示例代码:

for(var i:int=0;i<5;i++)
{
    var button:SimpleButton = new SimpleButton(...);
    ...
    button.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void
    {
        trace(i);
    });
}

...
Run Code Online (Sandbox Code Playgroud)

我想从点击按钮而不是4,4,4,4跟踪0,1,2,3 ..你知道我怎么能做到这一点?

anonymous-function actionscript-3

10
推荐指数
1
解决办法
1194
查看次数

标签 统计

actionscript-3 ×1

anonymous-function ×1