removing event listener

前端 未结 3 621
终归单人心
终归单人心 2021-01-27 06:09

I have learned this method of passing values with addEventLister. Here is the code:

for (var i:uint = 0; i < asteroids.length; i++)
{

     asteroids[i].x = M         


        
3条回答
  •  梦谈多话
    2021-01-27 06:39

    When you add an anonymous function as an event listener, the only time you can reasonably remove that event listener is inside the callback.

    public function changeValue(event:MouseEvent, otherArguments:Object):void
    {
    
        playSound(anote);
        trace(event.currentTarget);
        event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, arguments.callee);
    
    }
    

    Otherwise, you need to have a non-anonymous function in order to remove it.

提交回复
热议问题