Skip to main content
Known Participant
July 20, 2012
Question

How to reset/restart timer?

  • July 20, 2012
  • 1 reply
  • 3226 views

hello everyone

i am trying to restart my timer. i used

timer.reset();

but it won't work..

so i tried

timer.stop();

timer.reset();

timer.start();

and this is also not working.. timer is not reseting..

So can anyone tell me How can I restart my timer??

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
July 20, 2012

What you show should work.  It would also work without the timer.stop();  Maybe you should work it out in a separate file first to make sure you have everything proerly mapped.  Here's some code that works to help demo it:

var tm:Timer = new Timer(1000, 20);

function reportCount(evt:TimerEvent):void {
    trace(String(tm.currentCount));
}

tm.addEventListener(TimerEvent.TIMER, reportCount);

stage.addEventListener(MouseEvent.CLICK, restartClock);

function restartClock(evt:MouseEvent):void {
    tm.reset();
    tm.start();
}

tm.start();

Known Participant
July 21, 2012

i got this..

i have used similier code in my project.

well, i want to restart timer after some specific time.. for that i used below code.

var timer:Timer = new Timer(1000,0);

timer.start();

var cTime:int = getTimer();

if(cTime>=15000)

{

ResetTime();

}

function ResetTime():void{

timer.stop();

timer.reset();

timer.start();

}

but this is not working..

Participating Frequently
July 24, 2012

Please check below code.

import flash.events.TimerEvent;
import com.greensock.TimelineLite;

var timer:Timer = new Timer(1000,0);
timer.addEventListener(TimerEvent.TIMER,checkTime)
timer.start();

// This function is required so that once getTimer() will give you required number i.e. 1500 reset function will be called

function checkTime(e:TimerEvent)
{
      var cTime:int = getTimer();
      trace(cTime + " " + timer.currentCount) // currentCount will show that timer is restarted,
      if(cTime>=15000 && cTime<=16000)
      {
             ResetTime();
       }
}


function ResetTime():void
{
      trace("ResetTime")
      timer.stop();
      timer.reset();
      timer.start();
}

Hope that will solve your problem

Regards

Ritesh Newal