View Full Version : Flash digital clock


SUPER RP06
01-25-2006, 12:54 AM
Note: This tutorial is somewhat the same as backlightdesigns's, but there's something extra.

1. Open up the flash program
2. Create a new flash file, create 2 frames
3. You may change the size and bg colour
4. In Frame 1, In the text tool, draw 2 boxes set as dynamic, not static or input.
5. make one text box set as variable "date" and another as "time"
6. Using the Actions box in Frame 1, insert the following:
Year = new Date().getFullYear();
Month = new Date().getMonth()+1;
Day = new Date().getDate();
Hours = new Date().getHours();
Minutes = new Date().getMinutes();
Seconds = new Date().getSeconds();
Milliseconds = new Date().getMilliseconds();
Centiseconds = Math.floor(Milliseconds/10);
if (Month<10) {
Month = "0"+Month;
}
if (Day<10) {
Day = "0"+Day;
}
if (Hours<10) {
Hours = "0"+Hours;
}
if (Minutes<10) {
Minutes = "0"+Minutes;
}
if (Seconds<10) {
Seconds = "0"+Seconds;
}
if (Centiseconds<10) {
Centiseconds = "0"+Centiseconds;
}
Date_disp = Year+"/"+Month+"/"+Day
Time_disp = Hours+":"+Minutes+":"+Seconds+"."+Centiseconds

That would give you a 24-hour digital clock in yyyy/mm/dd format. If you like to have a dd.mm.yyyy format, modify the line which shows Date_disp so it shows like this:
Date_disp = Day+"."+Month+"."+Year
If you like a 12-hour clock, then insert the following from the 9th line down, below the centiseconds thing.
apm = "am"
if (Hours >= 12) {
apm = "pm";
Hours = Hours - 12;
}
if (Hours == 0) {
Hours = 12;
}
and add the thing in the Time_disp line:
+" "+apm
7. In frame 2 in the Actions window, add this: gotoAndPlay(1);
8. Test the movie
9. If everything's ok, save the file, and export it as .swf.