Back to Flash Portfolio

Digital Clock Animation

Download Adobe Flash Player 10

Action Script 3


// This line puts the date object into a variable
var now:Date = new Date();
// These 3 lines put the hours, minutes, and seconds into variables
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
// Conditional statement to set AM or PM according to hour(military time)
if (hours >= 12) {
ampm_txt.text = "PM";
} else { ampm_txt.text = "AM";
} // Conditional that converts military time to standard time display
if (hours > 12){
hours = hours - 12;
} if (hours == 00){
hours = 12;
} // Conditional that adds 0 to the front of any hour less than 10
if (hours < 10){
hours_txt.text = "0" + hours;
} else {
hours_txt.text = hours;
} // Conditional that adds 0 to the front of any minute less than 10
if (minutes < 10){
minutes_txt.text = "0" + minutes;
} else {
minutes_txt.text = minutes;
} // Conditional that adds 0 to the front of any second less than 10
if (seconds < 10){
seconds_txt.text = "0" + seconds;
} else {
seconds_txt.text = seconds;
}

Download Adobe Flash Player 10