Create A Flash Countdown Timer
This is an extension to my video tutorial which was originally posted on my YouTube channel. Unfortunately, when my old site’s servers were shut down, my source files went down too. So, here’s the extension. But first, watch the original video below:
For anyone who wants the source code. Here it is:
//This line tells Flash to start the countdown on load:
this.onEnterFrame = function() {
//Set the variables:
var today:Date = new Date();
var currentYear = today.getFullYear();
var currentTime = today.getTime();
//Now, here is where you can set the countdown date.
//The format for dates in flash are: Year, Month (0-11, 0 being January), Day.
//To countdown to the current year, use 'CurrentYear' or for a specific year, use '2011', '2012' etc.
var targetDate:Date = new Date(currentYear,11,25);
var targetTime = targetDate.getTime();
//Here's all the maths. Don't edit this unless you know what you're doing!
var timeLeft = targetTime - currentTime;
var sec = Math.floor(timeLeft/1000);
var min = Math.floor(sec/60);
var hrs = Math.floor(min/60);
var days = Math.floor(hrs/24);
sec = String(sec % 60);
if (sec.length < 2) {
sec = "0" + sec;
}
min = String(min % 60);
if (min.length < 2) {
min = "0" + min;
}
hrs = String(hrs % 24);
if (hrs.length < 2) {
hrs = "0" + hrs;
}
days = String(days);
var counter:String = days + ":" + hrs + ":" + min + ":" + sec;
time_txt.text = counter;
}
//The end!!
I’ve also attached the source files in both CS4 and CS5 format…
Flash CS4: Download the source files
Flash CS5: Download the source files


i REALLY need a tutorial for this type of countdown:
http://www.online-stopwatch.com/bar-timer/full-screen/?ns=../../s/10.mp3&nslen=1
i’m pretty new to flash but I don’t think it should be as difficult. The one cited looks very uncomplicated. Any help would be greatly appreciated! Thanks for this tut btw.
I’ll take a look, I’ll reply soon!
love this tutorial,it’s useful, but if i want to countdown to a specific time like someday at 20:00, what code should i write? thanks.
Interesting question, it’s something that’s been asked quite alot and it’s something I’m actively experimenting with. At the moment I can see no clear way of doing it, but when I do find out how to do it I will certainly post it on here straight away! Do stay tuned for more updates!
Hi, I also need the same thing. In a conference I’d like to insert a small video during coffee break with the countdown function so that all partecipants could see how much time is left for drinking coffee, etc. I want to define the time where it should start to countdown till zero.
I need to create a count down with years and centuries, just as the one in the movie “In Time” can you help me?