Tips & Tricks 5: Display digital time June 28, 2009

Tips & Tricks 5: Display digital time

by flashuser in Actionscript 2.0, Flash Tips & Tricks

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().



Get Adobe Flash player

Subscribe to our RSS Feed and follow us on Twitter

Enjoy this post?

Help us grow this site and share the content with others among you.

img-delicious img-digg img-twitter
img-stumbleupon img-facebook img-mixx

Leave a Comment

Note: You can get a Gravatar account for free so your avatar can be shown when you post a comment on any website that supports gravatars.