Copy link to clipboard
Copied
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??
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
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.. ![]()
Copy link to clipboard
Copied
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
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more