Skip to main content
Known Participant
May 26, 2009
Answered

Timer Start and Stop problem

  • May 26, 2009
  • 1 reply
  • 1363 views

I have a timer set up like this:

function headlineTimer() {
    var timer:Timer = new Timer(3000, 20);
    timer.addEventListener(TimerEvent.TIMER, timerComplete);
    timer.start();
}
function timerComplete(e:TimerEvent):void{
    trace("times up");
    nextFrame();

}

The problem is I cant figure out how to stop it or reset it after it goes to the next frame.  Can anyone help me with this? thanks in advance.

This topic has been closed for replies.
Correct answer kglad

try:

var timer:Timer;
stop();
headlineTimer();

function headlineTimer() {
    timer = new Timer(3000, 20);
    timer.addEventListener(TimerEvent.TIMER, timerComplete);
    timer.start();
}
function timerComplete(e:TimerEvent):void{
    trace("times up");
    stopTimer(); // this really needed.
    nextFrame();
}
function stopTimer():void {
    timer.stop();
}

1 reply

kglad
Community Expert
Community Expert
May 26, 2009

look at the timer class in the help documents.  it shows there are 3 methods.  you know how to use one of them.  the other two are stop() and reset().

Known Participant
May 26, 2009

So if I do this :

function headlineTimer() {
    var timer:Timer = new Timer(3000, 20);
    timer.addEventListener(TimerEvent.TIMER, timerComplete);
    timer.start();
}
function timerComplete(e:TimerEvent):void{
    trace("times up");
    stopTimer();
    nextFrame();
}
function stopTimer(e.TimerEvent):void {
    timer.stop();
}

It doesnt work it throws an error. Why is that?

kglad
Community Expert
Community Expert
May 26, 2009

because you didn't call headlineTimer().  then it will generate a run-time error.