Skip to main content
January 17, 2013
Question

How do I repeat a function that starts immediately?

  • January 17, 2013
  • 1 reply
  • 426 views

Hi,

I am using a Timer function to repeat a function however the function only begins (and repeats) after the period set eg. 5 seconds not immediately.

Here is an example of the code:

var myTimer:Timer = new Timer(2000,8);

myTimer.addEventListener(TimerEvent.TIMER, timerListener);

function timerListener (e:TimerEvent):void{

trace("Timer is Triggered");

}

myTimer.start();

Is there any way to make the function start immediately then repeat?

Thanks


Chris

This topic has been closed for replies.

1 reply

Inspiring
January 17, 2013

after timer.start()

add

myTimer.dispatchEvent(new TimerEvent(TimerEvent.TIMER));

this will trigger your function immediately

January 17, 2013

That's really useful.

Thanks!