Page 1 of 1

pause/resume timer

Posted: Sun Nov 18, 2007 12:50 am
by asifshahid
I need an action script code to play a timer. I can pause it, but I can't resume it. Help me out!

The code I used for Timer:
var time:Number = 0;
function updateMinutes() {
time++;
timer.text=time;
/*timer is the instance name of dynamic text which shows the counting in second.*/
}
timeInterval=setInterval(updateMinutes, 1000);

And for pause:
on (release) {
timer=pause();
}

And for resume:
Need the code

Posted: Tue Nov 20, 2007 5:51 am
by zahidur59
put this on the first frame of root timeline

Code: Select all

var time:Number = 0;
function updateMinutes() {
	var time = Number(timer.text);
	time++;
	timer.text=time;
/*timer is the instance name of dynamic text which shows the counting in second.*/
}
var timeInterval = setInterval(updateMinutes, 1000); 
_resume.enabled = false;
_pause.enabled = true;
Assuming the pause and resume buttons have the instance names _pause and _resume, respectively,

for _pause button -

Code: Select all

on (release) {
	clearInterval(timeInterval);
	_resume.enabled = true;
	_pause.enabled = false;
}
for _resume button -

Code: Select all

on (release) {
	_root.timeInterval = setInterval(updateMinutes, 1000); 
	_resume.enabled = false;
	_pause.enabled = true;
}
Note that this is not accurate. You will loose the fractions of the second passed just before the Pause button was clicked. For a precise one, study some on getTimer() function.

Oh and the pause() used in your code is for a totally different purpose. DON'T confuse it with this scenario.

Posted: Tue Nov 20, 2007 3:50 pm
by asifshahid
wwooooooooowwww, it's working!!!!!!.......many many thanks Zahid Bhai.....ya it takes less than a second when i press the resume button.....but for now my project don't mind that :)....If I get anything about getTimer() I will post here. Thanks again.