It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Flash Forum

how to do a timer

Moderator: Phate

how to do a timer

Postby legalnine on Mon Jan 08, 2007 12:40 pm

hi there!! is there such a thing as countdown timer in flash 8? like from 30 secs all the way to 0.

if there is.. could anyone pleaseee teach mi how to do one?

thanks thanks
legalnine
 
Posts: 5
Joined: Thu Jan 04, 2007 4:58 pm

Postby gszauer on Thu Jan 11, 2007 9:23 pm

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: Select all
//////////////////////////////////////////
//    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();
};
gszauer
 
Posts: 3
Joined: Thu Jan 11, 2007 8:55 pm


Who is online

Users browsing this forum: No registered users and 0 guests