How do you bind a variable to a function in as3

后端 未结 5 1494
孤独总比滥情好
孤独总比滥情好 2020-12-21 16:08

I have this code:

for each(var tool in tools){
tool.addEventListener(MouseEvent.MOUSE_DOWN, function(){
    trace(tool); //Always the last tool  
 });
}
         


        
5条回答
  •  没有蜡笔的小新
    2020-12-21 16:52

    try to do:

    for each(var tool in tools){
    var t = tool;
    t.addEventListener(MouseEvent.MOUSE_DOWN, function(){
        trace(t); //Always the last tool  
    });
    }
    

提交回复
热议问题