Question

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?

Was it helpful?

Solution

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();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top