How to Make a Countdown Clock on Flash
Adobe Flash includes the Flash scripting language, ActionScript, which controls and creates the functionality in animations. Perhaps you want to include a countdown clock in your multimedia project. A countdown clock can provide your users with day, hour, minute and second updates on the time remaining until a certain event. Make a countdown clock in Flash using ActionScript functions and methods.
Instructions
-
-
1
Launch Flash. Select "File" and "New" to create a new project. Select the "Flash File (ActionScript 3.0)" option and click "OK."
-
2
Select the Text tool from the Tools panel and create a text box. Set the text area to "Dynamic Text" or "TLF Text" from the "Properties" panel. Type "clockTxt" for the "Instance Name."
-
-
3
Click on the first frame of the timeline. Open the Actions panel by pressing "F9," Type the ActionScript code to create a clock that counts down to the next year. The lines that begin with // are descriptions, not part of the code:
// register the function
addEventListener('enterFrame',clock_handler);
// this is called repeatedly
function clock_handler(evt:Event):void{
// the current date
var today:Date = new Date();
// the current Year
var currentYear = today.getFullYear();
// the current time
var currentTime = today.getTime();
// make and store the end date (next new year)
// modify to fit your need
var endDate:Date = new Date(currentYear+1, 0, 1);
var endTime = endDate.getTime();
// time left
var timeLeft = endTime-currentTime;
var sec = Math.floor(timeLeft/1000);
var min = Math.floor(sec/60);
var hours = Math.floor(min/60);
var days = Math.floor(hours/24);
// result of remaining value variable. convert seconds to string
sec = String(sec%60);
// if reduced < 2 add a 0
if (sec.length<2) {
sec = "0"+sec;
}
min = String(min%60);
if (min.length<2) {
min = "0"+min;
}
hours = String(hours%24);
if (hours.length<2) {
hours = "0"+hours;
}
days = String(days);
if (timeLeft>0) {
// combine values into one string
var counter:String = days+":"+hours+":"+min+":"+sec;
clockTxt.text = counter;
} else {
trace("It's A Brand New Year!");
var newTime:String = "00:00:00:00";
clockTxt.text = newTime;
removeEventListener('enterFrame',clock_handler);
}
}
-
4
Select "Control" and "Test Movie" to test the countdown clock.
-
1
References
Resources
- Photo Credit Burke/Triolo Productions/Brand X Pictures/Getty Images