pause/resume timer

Post Reply
User avatar
asifshahid
Insanely Distorted
Insanely Distorted
Posts: 4329
Joined: Tue Oct 16, 2007 2:35 pm
Full Name: Asif Shahid
x 37

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


User avatar
zahidur59
Posts: 128
Joined: Sun Oct 21, 2007 4:49 pm
Full Name: Khandakar Zahidur Rahaman
Expertise: Jack of all, master of NONE

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.
User avatar
asifshahid
Insanely Distorted
Insanely Distorted
Posts: 4329
Joined: Tue Oct 16, 2007 2:35 pm
Full Name: Asif Shahid
x 37

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.
Post Reply

Return to “Flash”