开发者

Removing event listeners for local variables?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜