How to Make a Countdown in ActionScript
Created by Adobe Software for developing Flash-based web applications, ActionScript is a language that can be used to create both rich Internet applications and simple ones, such as countdown timers. Making a countdown timer in ActionScript is fairly straightforward and can be a good practice exercise for novice ActionScript programmers.
Instructions
-
-
1
Launch Adobe Flash or Flex, which are programs used to develop and edit ActionScript files. Create a new ActionScript 3 document.
-
2
Create a new object for the date by using the following code:
var endDate:Date = new Date(2010, 5, 11);
-
-
3
Add a timer that updates the time every section by adding the following line of code:
var timer:Timer = new Timer(1000);
-
4
Create a function that listens to the timer and automatically updates it by using the following code and modifying it to fit your needs:
timer.addEventListener(TimerEvent.TIMER, updateTime);
timer.start();
-
5
Create a function to calculate the time remaining by using the following code:
function updateTime(e:TimerEvent):void{
var currentDate:Date = newDate();
vartimeLeft:Numer = endDate.getTime() - currentDate.getTime();
-
6
Convert the time that is remaining into minutes, hours, days and seconds by adding the following lines to the updateTime function:
var seconds:Number = Math.floor(timeLeft / 1000);
var minutes:Number = Math.floor(seconds / 60);
var hours:Number = Math.floor(minutes / 60);
var days:Number = Math.foor(hours / 24);
seconds %= 60;
minutes %= 60;
hours %= 24;
-
7
Finalize the countdown timer by converting the numbers to strings with the following lines of code:
var sec:String = seconds.toString();
var min:String = seconds.toString();
var hrs:String = hours.toString();
var d:String = days.toString();
-
1