Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

How to reset/restart timer?

Explorer ,
Jul 20, 2012 Jul 20, 2012

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??

TOPICS
ActionScript
3.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 20, 2012 Jul 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();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 20, 2012 Jul 20, 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..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 24, 2012 Jul 24, 2012
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines