Skip navigation
Currently Being Moderated

How to reset/restart timer?

Jul 20, 2012 2:23 AM

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

 
Replies
  • Currently Being Moderated
    Jul 20, 2012 4:32 AM   in reply to sachin_mak

    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();

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 24, 2012 2:03 AM   in reply to sachin_mak

    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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points