Flash Countdown Timer

In this tutorial, you will learn how to create a timer in Adobe Flash that will count down the time to a given date in days, hours, minutes, and seconds. If you were looking for a great Flash tool for counting down holidays, birthdays, etc, this is the tutorial for you.

Also, this Flash countdown timer tutorial allows you to preset any day of your choice with in AS2 and AS3. Have fun!

Create the Flash Countdown Timer in AS2

This tutorial will go over the basics on constructing a Flash countdown timer within Actionscript 2.0.

Step 1: Create a dynamic text field with the string value of “00:00:00:00″. Note:this is simply to get the text field to the size needed for the dynamic content.

Step 2: Delete the string value of text field and name the text field “time_txt”.

Step 3: Create a new layer named “actions” and insert the following code in the first keyframe:

Source File: REMOVED

Update: Based on your feedback on this tutorial, I decided to create a hassle free CountdownTimer AS3 class that will assist in creating your very own flash countdown timer. Learn how to create a Flash Countdown in AS3 using this class.

//onEnterFrame allows for a function to be called every tick
this.onEnterFrame = function()
{
	//Stores the current date
	var today:Date = new Date();
	//Stores the Current Year
	var currentYear = today.getFullYear();
	//Stores the Current Time
	var currentTime = today.getTime();
	//Creates and stores the target date
	var targetDate:Date = new Date(currentYear,11,25);
	var targetTime = targetDate.getTime();
	//Determines how much time is left.  Note: Leaves time in milliseconds
	var timeLeft = targetTime - currentTime;
	var sec = Math.floor(timeLeft/1000);
	var min = Math.floor(sec/60);
	var hours = Math.floor(min/60);
	var days = Math.floor(hours/24);
	//Takes results of var remaining value.  Also converts "sec" into a string
	sec = String(sec % 60);
	//Once a string, you can check the values length and see whether it has been reduced below 2.
	//If so, add a "0" for visual purposes.
	if(sec.length < 2){
		sec = "0" + sec;
	}
	min = String(min % 60);
	if(min.length < 2){
		min = "0" + min;
	}
	hours = String(hours % 24);
	if(hours.length < 2){
		hours = "0" + hours;
	}
	days = String(days);

	if(timeLeft > 0 ){
		//Joins all values into one string value
		var counter:String = days + ":" + hours + ":" + min + ":" + sec;
		time_txt.text = counter;
	}else{
		trace("TIME'S UP");
        var newTime:String = "00:00:00:00";
        time_txt.text = newTime;
        delete (this.onEnterFrame);
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *