开发者

Removing event listeners for local variables?

开发者 https://www.devze.com 2023-02-10 10:07 出处:网络
Do you have to remove event listeners on variables with local scope开发者_C百科? By this I mean...does the event listener still exist if the variable only exists as long as the function/method is runn

Do you have to remove event listeners on variables with local scope开发者_C百科? By this I mean...does the event listener still exist if the variable only exists as long as the function/method is running?

private function startSomething():void
        {
            whatever.start();
            var t:Timer = new Timer(2000,1);
            t.addEventListener(TimerEvent.TIMER, stopSomething, false, 0, true);
            t.start();
        }

private function stopSomething(e:TimerEvent):void
        {
            // do you have to remove the event listener here??

        }


As the timer will fire only once, there is no need to remove the listener.


If you really need to do it, you can do :

Timer(e.currentTarget).removeEventListener(TimerEvent.TIMER, stopSomething);

Almost all event target/currentTarget properties refers to the trigger object.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号