Copy link to clipboard
Copied
Hi,
I'm brand new to flash, I have CS4 profesional.
I found a video online on how to make a countdown timer and I can't seem to get it to work. The video looks like it's using ActionScript2 so I did the same.
here's the script I'm using, if anyone can point out anything I'm doing wrong I'd apprecitate it.
this.onEnterFrame = function() {
var today:Date = new Date ();
var currentYear = today.getFullYear();
var currentTime = today.getTime();
var targetDate:Date = new Date (2012,07,12);
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;
}
1 Correct answer
That worked I changed from ActionScript 3 to ActionScript 2 and the counter is working.
Thanks for all your help I owe you one.
dom...
Copy link to clipboard
Copied
do you have a textfield named time_txt on-stage? if yes, what's not working? if no, put one on-stage and retest.
Copy link to clipboard
Copied
Hi thanks for the reply.
Yes I do have a textfield called Text_txt on the stage, when I hit command return to test the movie I get these errors.
Scene 1, Layer 'Action', Frame 1, 1180: Call to a possibly undefined method string. sec = string (sec % 60);
Scene 1, Layer 'Action', Frame 1, 1180: Call to a possibly undefined method string. min = string (min % 60);
Scene 1, Layer 'Action', Frame 1, 1180: Call to a possibly undefined method string. hrs = string (hrs % 24);
Scene 1, Layer 'Action', Frame 1, 1180: Call to a possibly undefined method string. sec = string (days);
Thanks again
Copy link to clipboard
Copied
Change string to String
Copy link to clipboard
Copied
that's because there is no string class. it's the String class:
this.onEnterFrame = function() {
var today:Date = new Date ();
var currentYear = today.getFullYear();
var currentTime = today.getTime();
var targetDate:Date = new Date (2012,07,12);
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;
}
p.s. i don't think you need to cast those numbers as strings.
Copy link to clipboard
Copied
I changed the s to S and that got ride of those errors, I'm getting one more
Warning: 1090: Migration issue: The onEnterFrame is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'enterFrame', callback_handler).
this.onEnterFrame = function() {
I'm getting this from an online Tutorial heres the address to the Tutorial
http://www.entheosweb.com/Flash/video_tutorials/countdown_timer.asp
dom..
Copy link to clipboard
Copied
Try changing your Publish settings to be for AS2 instead of AS3, otherwise you'll need different code for the etner frame for AS3
Copy link to clipboard
Copied
That worked I changed from ActionScript 3 to ActionScript 2 and the counter is working.
Thanks for all your help I owe you one.
dom...
Copy link to clipboard
Copied
You're welcome. It should have been caught after seeing the error messages in the first place... thoise were AS3 1180 errors, AS2 more often doesn't provide any.
Copy link to clipboard
Copied
About 8 years ago I used to use Director but it's been awhile. This is my first look at Flash, can you point me to some good tutorials??
Thanks again
dom...
Copy link to clipboard
Copied
If you're just picking up on Flash, I'd recommend you avoid AS2 and learn AS3 from the start instead. As far as tutorials go, if you have an idea for something you want to develop, the best first step is to use Google and search using terms like "AS3 whatever tutorial" where whatever is the feature or type of project you want to learn about. Beyond that gotoandlearn.com has numerous well-prepared tutorials, as does Lynda.com (fee-based), and there are others to be found at http://slekx.com/as3-intro/ and http://tv.adobe.com/product/flash/ In short, there are plenty of resources, you just need to become savvy in the ways of finding them, which can all start with Google.
Copy link to clipboard
Copied
Thanks again, I'll check out those sites, I'm sure I'll be back with many
more questions.
dom...

