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.
September 14th, 2010 at 8:49 am
I have a rather simple question: I have a working .fla index file and I would like to incorporate the timer into it, obviously (running cs5). What’s the best setup for including the whole timer on my page? I can’t seem to get it to show up, though I’m not getting any compiler errors.
September 14th, 2010 at 4:29 pm
Hi Nate,
A variety of things could be going wrong, but I’m guessing you copied the timer graphics without connecting the script to them. Notice in “counter.fla” that the document class is set to “com.anselmbradford.Main” in the Properties panel for the whole file. If this didn’t get copied the code won’t be attached to the graphics.
December 11th, 2010 at 4:13 pm
Hi Nate,
I tried to run your script – it works, but the countdowan appears to be way off – 30 days or so? Any clue?
December 11th, 2010 at 4:20 pm
It’s ok: I just discovered that flash starts the month array at 0 instead of 1. So my date was a month off, 30 days…
Thanks for the script.
December 13th, 2010 at 11:07 am
Hi can you help I need a 2 minute countdown timer in Action Script 3 for a project I’m working on at uni. I would also like it to say times up at the end of timer can you help me.
Thank you
Chris
December 14th, 2010 at 4:05 am
Nice implementation!
December 20th, 2010 at 5:26 am
Can anybody help me in Action Script 3 I am trying to create a count down timer for 2 minutes but I have had no luck so far.
Thank you
Chris
December 20th, 2010 at 10:36 pm
Hi Chris,
I’m afraid I don’t have time at the moment to build help build one for you. But I could probably answer specific questions about problems with your implementation. Check out the source code download above and work from there. Cheers!
December 29th, 2010 at 12:44 am
[...] Title: Creating a date countdown timer in ActionScript 3 / Flash Technology: Flash AS3 Code Site: Click here Demo Site: Click here Title: Flash simple timer/countdown Technology: [...]