Frage

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?

War es hilfreich?

Lösung

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();
    }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top