Hello,
I am having trouble getting my dynamic text field to populate based on a countdown ActionScript. My dynamic text field’s attribute name is time_txt and is set to Dynamic Text in the Properties panel. Here is my code:
this.onEnterframe = function() {
//Gets current date, year, and time
var today:Date = new Date ();
var currentYear = today.getFullYear();
var currentTime = today.getTime();
//Denotes target date that we are counting down to
var targetDate:Date = new Date (2008,06,12);
var targetTime = targetDate.getTime();
//Calculates the actual time left between the current date and target date
var timeLeft = targetTime - currentTime;
//Converst milliseconds into seconds, minutes, hours, and days
var sec = Math.floor(timeleft/1000);
var min = Math.floor(sec/60);
var hrs = Math.floor(min/60);
var days = Math.floor(hrs/24);
//Stores remainders of seconds so 130 seconds doesn't look like 2 minutes, 130 seconds, but rather 2 minutes 10 seconds
//Converts sec to a string
//Accounts for sec values under 10 so that 5 reads 05
sec = string(sec % 60);
if (sec.length < 2) {
sec = "0" + sec;
}
//Stores remainders of minutes so 130 seconds doesn't look like 2 hours, 130 minutes, but rather 2 hours 10 minutes
//Converts min to a string
//Accounts for min values under 10 so that 5 reads 05
min = string(min % 60);
if (min.length < 2) {
min = "0" + min;
}
//Stores remainders of hours so 25 hours doesn't look like 1 day, 25 hours, but rather 1 day 1 hour
//Converts hrs to a string
//Accounts for hrs values under 10 so that 5 reads 05
hrs = string(hrs % 24);
if (hrs.length < 2) {
hrs = "0" + hrs;
}
//Converts days into a string
days = string(days);
//String together days, hours, minutes, seconds
var counter:String = days + ":" + hrs + ":" + min + ":" + sec;
//Update dynamic text field
time_txt.text = counter;
}
Any ideas?
Thanks!