Aug
03
2009
Creating a date countdown timer in ActionScript 3 / Flash
Creating a countdown timer in ActionScript is quite easy. The essentials of it are:
- Specify a target date to countdown to using the Date class.
- Create a Timer instance to check the countdown time each second or so.
- At each tick of the timer calculate the number of milliseconds between now and the target date.
- Determine how many days, hours, minutes, seconds, etc. that number of milliseconds is equal to.
- Update the graphics to reflect the amount of time left.
The following is an example of a countdown timer, with a link to the source code below. This utilizes a reusable class file for the countdown timer. All code specific to this particular implementation can be found in com/anselmbradford/Main.as.
This movie requires Flash Player 9

March 8th, 2010 at 4:17 am
I got a question about making the countdown timer blink in my provided example. To do this change the update interval (currently at one second) and change the
textColorproperty on every update.First open
CountDown.asand find:and change to:
So that it fires every half a second.
Then open
Main.asand find:Replace this with:
This checks if the digit is updating, if it is, change the color to red, otherwise change it to black. Since the timer is firing every half a second the seconds will blink red.