gszauer
Joined: 11 Jan 2007 Posts: 3
|
Posted: Thu Jan 11, 2007 10:23 pm Post subject: Re: how to do a timer |
|
|
There is a built in function, but i wrote one that i use, it makes more sence to me.
This will output time in mm:ss format (m-minutes, s-seconds).
There are 2 variables you need to change, they are commented on in the script.
After calling the script in an enter frame, the remaining time becomes avalible as _root.currentTime
Just copy/paste this script into a blank frame on the root timeline to see it in action.
| Code: |
//////////////////////////////////////////
// Code Provided By Gabor Szauer //
// http://szauer.net //
/////////////////////////////////////////
time = 150; // The time you want to count down (In seconds)
fps = 12; // The FPS of your movie (12 by default)
time_left = time*fps;
function countdown() {
time_left--;
minutesLeft = Math.floor(((time_left/12)/60));
secondsLeft = Math.floor(((time_left/12)%60));
if (secondsLeft<10) {
secondsLeft = "0"+secondsLeft;
}
if (minutesLeft<10) {
minutesLeft = "0"+minutesLeft;
}
_root.currentTime = minutesLeft+":"+secondsLeft;
trace(currentTime);
}
_root.onEnterFrame = function() {
countdown();
}; |
|
|