SEARCH

Count Down Timer

Step 1

Open new document. Make background for your timer.

image 1

Step 2

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

image 2

Step 3

Set your text to Dynamic Text.

image 3

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)

image 4

Step 5

Now add one more Layer, for action.

image 5

Step 6

On frist frame write/copy action code.

image 6

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.

image 7

Step 9

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

Count Down Timer

Final movie

subscribe to newsletter