Jr. Mathews
Jr. Mathews

Reputation: 21

Removing a function and adding it again

I know it's possible to add and remove functions via event listener, but I was curious to know if it's possible to add/remove a function not by event listener. So I guess a custom function

function timer(event:TimerEvent)
{
  example();
}

function example():void
{
  trace("example");
}

Would it be possible to remove the example function then add it again?

Upvotes: 0

Views: 62

Answers (1)

Florent
Florent

Reputation: 12420

As you said, the common way is to use event listeners:

mytimer.removeEventListener(TimerEvent.TIMER, timer);

If you don't want to remove the listener you could use a flag to toggle example call:

var tick = false;
function timer(event:TimerEvent)
{
    if (tick) {
        example();
    }
}

Upvotes: 1

Related Questions