ActionScript 3 Digital Clock Class
Thu Jan 21 04:10:47 2010
Something as simple as putting the time on your site shouldn't be a difficult task and so I thought I would share a quick class with you that when instantiated creates and Textfield and tells the current time.
Here's the code.
import DigitalClock; var clock:DigitalClock = new DigitalClock(); var clockGMT:DigitalClock = new DigitalClock(true); addChild(clock); addChild(clockGMT); clock.x = 10; clockGMT.x = 100;
Here's the result
In the example above, we import and make two instances of the class DigitalClock. I have named them 'clock' and 'clockGMT' for obvious reasons.
You will noticed that we pass the Boolean
true to the clockGMT instantiation to create a clock that displays Greenwich Mean Time (GMT) which is the local time in the UK. If you don't pass
false the class will default to the local time (
false) of the computer viewing it.
After that, all that's left is to add the clocks to the display list using
addChild() passing in the name of each instantiation. I have also set the
x position of the clocks so they don't appear on top of one another.