redconservatory
redconservatory

Reputation: 21934

Removing event listeners for local variables?

Do you have to remove event listeners on variables with local scope? 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??

        }

Upvotes: 0

Views: 510

Answers (2)

Simon Eyraud
Simon Eyraud

Reputation: 2435

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.

Upvotes: 3

taskinoor
taskinoor

Reputation: 46037

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

Upvotes: 3

Related Questions