Create Flash Count Down Timer

January 1, 2010

How To

Step 1

Open new document. Make background for your timer.

Step 2

Add text for time (HH:MM:SS:FS) like on picture below.

Step 3

Set your text to Dynamic Text.

Step 4

Add him a Instance name “count_down” (It’s important to don’t change this name, or you have to change name in code later)

Step 5

Now add one more Layer, for action.

Step 6

On frist frame write/copy action code.

Step 7

Here is the code.

stop();

start_time = getTimer();
countdown = 10000;
onEnterFrame = function () {
elapsed_time = getTimer()-start_time;
_root.count_down.text = time_to_string(_root.countdown-elapsed_time);
};
function time_to_string(time_to_convert) {
elapsed_hours = Math.floor(time_to_convert/3600000);
remaining = time_to_convert-(elapsed_hours*3600000);
elapsed_minutes = Math.floor(remaining/60000);
remaining = remaining-(elapsed_minutes*60000);
elapsed_seconds = Math.floor(remaining/1000);
remaining = remaining-(elapsed_seconds*1000);
elapsed_fs = Math.floor(remaining/10);
if (elapsed_hours<10) {
hours = “0″+elapsed_hours.toString();
} else {
hours = elapsed_hours.toString();
}
if (elapsed_minutes<10) {
minutes = “0″+elapsed_minutes.toString();
} else {
minutes = elapsed_minutes.toString();
}
if (elapsed_seconds<10) {
seconds = “0″+elapsed_seconds.toString();
} else {
seconds = elapsed_seconds.toString();
}
if (elapsed_fs<10) {
hundredths = “0″+elapsed_fs.toString();
} else {
hundredths = elapsed_fs.toString();
}
if (elapsed_time > 9999) {
gotoAndPlay(2);
} else {
return hours+”:”+minutes+”:”+seconds+”:”+hundredths;
}}

Settings:

countdown = 10000; // number of seconds * 1000. In this case we have 10 seconds count down timer

if (elapsed_time > 9999) { // IMPORTANT – here must be number wich you set for “countdown” (in this case 10 000) minus 1. In this case: 10 000 – 1 = 9999

Step 8

Now copy all frames to 2nd frame of your flash file.

Step 9

Clear Instance name for Dynamic Text on 2nd frame. That’s it. Test your movie and test your count down timer.

Final movie

, , , , ,

7 Responses to “Create Flash Count Down Timer”

  1. Ryan Says:

    How do you pause it. I have searched the web. HELP ME PLEASE. I cannot get anything to work. I need a pause and resume on a countdown timer.

  2. mae Says:

    saun wa man d.i

  3. Tee Says:

    Thankx, I found your code very helpful. Is there any less code you can use for the countdown? Coz this one has too much of code.

  4. SRIV Says:

    I am up to step 6 but i cannot find where actions-frame is, to put in the code? can u help me

  5. SRIV Says:

    I found it, but now i’m having trouble with step 8, how do i copy da frames?

  6. Jon Says:

    This looks great but I want to count up to a specific number from zero stopping at my target. Can this code be altered to suit that need or do I need an altogether different code? Instead of a time format it’s in ones,tens, hundreds,thousands, millions.

  7. Goofan Says:

    I get alot of errors on every “var” you use in the code.. is there anything specific required to make this?

Leave a Reply