Creating anonymous functions in loop with not the same arguments

Posted by onio9 on Stack Overflow See other posts from Stack Overflow or by onio9
Published on 2010-12-25T13:44:05Z Indexed on 2010/12/25 13:54 UTC
Read the original article Hit count: 208

Hello! I want to make in loop set of buttons, and add to them some events, but anonymous functions is the same. I write example code:

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

...

And I want to trace 1,2,3.. from click buttons instead of 4,4,4,4 .. Do you know how can I make this ?

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about anonymous-function