June 28, 2009
Tips & Tricks 5: Display digital time
For today’s trick I will show how you can display digital time in Flash.
1. Using the Text Tool(T) create 3 Textboxes(hours, minutes, seconds).
2. Give each one a name in the Var field of the Properties Panel.(for this example I use h – hours, m – minutes, s – seconds).
3. Write the following Actionscript code:
var dt
var timeint;
date = new Date();
h = date.getHours();
m = date.getMinutes();
s = date.getSeconds();
timeint = setInterval(displayZ, 1000);
function displayZ() {
date = new Date();
h = date.getHours();
m = date.getMinutes();
s = date.getSeconds();
if (h<10) {
h = "0"+h;
}
if (m<10) {
m = "0"+m;
}
if (s<10) {
s = "0"+s;
}
}
4. If you want to display GMT Time(the example above uses Local Time) replace getHours() with getUTCHours, getMinutes() with getUTCMinutes() and getSeconds() with getUTCSeconds().







Leave a Comment