As2 Countdown Timer

addEventListener ('enterFrame',callback_handler);

this.onEnterFrame = function (){

var today: Date = new Date();
var currentYear = today.getFullYear();
var currentTime = today.getTime();

var targetDate:Date = new Date(currentYear,6,28);
var targetTime = targetDate.getTime();

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.lenth <10) {
min = "0" + min;
}
hrs = string(min % 60);
if (hrs.lenth <10) {
hrs = "0" + hrs;
}
days = string(days);

var counter : String = days + ":" + hrs + ":" + min + ":" + sec;
time_txt.text = counter;
}

2 Comments

You must be logged in to post a comment.


  1. Thanks DJ. On the site 'submitted by' is the user that posted the snippet not the author. Snippets that are 'authored by', are snippets by the actual author.

    So yay not my creation. I copy pasted this one with the errors in it.


  2. I know this is old but there's a bunch of typos in it... length misspelled, hrs calculated with the minutes' calculation... length < 10 instead of 2.