English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am trying to create a countdown timer in flash. I have gather this from online searching however the numbers do not show up. I have no idea what i am doing wrong. I have embed the fonts and everything. Is the coding wrong?

this.onEnterFrame = function() {

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

var targetDate:Date = new Date(2007,11,25);
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.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;
}

2007-03-22 04:21:09 · 2 answers · asked by spklingstr 1 in Computers & Internet Programming & Design

ok so after doing the trace thing it is telling me that my text is undefined. what do i do next?

2007-03-22 06:13:27 · update #1

2 answers

I have tested your code and it is work probably.Notice that the code might not work with you that due 'the text box was not named or the code have no access to the text box .
Also I have uploaded the fla file which used by me and here is the link:

http://www.geocities.com/m.zatari/Counter.fla


Note: The trace(); command didn't work because of the statement can't access the variable counter from outside the function , So you should use it inside the function.

Good Luck,,,

2007-03-25 03:23:31 · answer #1 · answered by Me 3 · 0 0

There is nothing wrong with the code.
ensure that:
1. the function is executing
2. the text field exists and is targeted properly


trace out the result to see if is correct, and then trace out the text field to see if it exists:
trace(counter);
trace(time_txt);


if nothing comes up your func is not executing.
if the latter traces "undefined" then your text field does not exist.

2007-03-22 11:29:12 · answer #2 · answered by Fabian 2 · 0 0

fedest.com, questions and answers