In this tutorial, you'll learn how to create a timer in Flash that will count down the time to a given date in days, hours, minutes, and seconds. This is a great tool for counting down to holidays, birthdays, anniversaries, etc.
Of all the timers I’ve researched on the net, this is the cleanest and easiest to follow. I’ve been looking for a timer that will countdown for a month and reset itself to count down the next month. IE: The countdown is for January, so the countdown is from Jan 1st until Jan 31st. Once the timer reaches 12:01 on Feb 1st the countdown starts again and displays the new month but counts down the 28 or 29 dyas in Feb and so on until year end and renews itself in 2008 or the timer can be made to stop and 2008 can be input manually as the new year in the .fla I tried to modify this .fla, by adding a month var after the year var but couldn’t get it working.
Any ideas
I don't know flash very well, but I think something like the code below should do what you want. Keep in mind that the daysPerMonth array I created would need manual changes since February alters. I imagine this could be made to work automatically, but since I don't know Flash very well I don't know how to do this.
this.onEnterFrame = function() {
var today:Date = new Date();
var currentYear = today.getFullYear();
var currentTime = today.getTime();
var currentMonth = today.getMonth();
var daysPerMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var targetDay = daysPerMonth[currentMonth];
var targetDate:Date = new Date(currentYear, currentMonth, targetDay);
// etc.
}
No, I don’t have Flash installed so I’m just guessing that this will work. I think the only other thing that may be needed is a time parameter added to the targetDate so it counts down to 11:59pm prior to switching to the next month. The time most likely would need to be added after the targetDay parameter in the Date call. Let me know if it works out for you.
it works for me, but i would like the coundown to be able to count until specific hour with minutes example: till 1 july to 1 pm. i dont know actionscript so i cant modify it. and after that count up from the date. Any one can write the script for me?
What I have above should do what you want, the time can be added to the targetDate variable like this:
var targetDate:Date = new Date(currentYear, currentMonth, targetDay,
hour, minute, second, milisecond);
hour: An integer from 0 (midnight) to 23 (11 p.m.).
minute: An integer from 0 to 59. This parameter is optional.
second: An integer from 0 to 59. This parameter is optional.
millisecond: An integer from 0 to 999. This parameter is optional.
As far as counting to another date automatically that could be done also, but would need to have the data provided by you if the dates were not a specific distance apart. You could simply enter in the new date/time manually after the given target date is reached. I would write the script for you, but like I said I don’t have Flash installed so I wouldn’t be able to test it.
BTW - this doesn’t work perfectly. For some reason when I just used the tutorial as is the seconds only displayed a “0″ when they were less than 10. I changed sec.length
Sorry I didn’t get back to you sooner, it seems the comments didn’t show up in the log as a new comment either. I will look into that problem. Since I didn’t see the rest of the comment I can’t say for sure what the problem is, but if only a zero is showing I would guess that the variable for seconds doesn’t contain any data. I am only guessing that is the problem, and assuming the section that adds the leading zero to the seconds is ok.
Of all the timers I’ve researched on the net, this is the cleanest and easiest to follow. I’ve been looking for a timer that will countdown for a month and reset itself to count down the next month. IE: The countdown is for January, so the countdown is from Jan 1st until Jan 31st. Once the timer reaches 12:01 on Feb 1st the countdown starts again and displays the new month but counts down the 28 or 29 dyas in Feb and so on until year end and renews itself in 2008 or the timer can be made to stop and 2008 can be input manually as the new year in the .fla I tried to modify this .fla, by adding a month var after the year var but couldn’t get it working.
March 20th, 2007 at 4:31 amAny ideas
Hi 2evisual,
I don't know flash very well, but I think something like the code below should do what you want. Keep in mind that the daysPerMonth array I created would need manual changes since February alters. I imagine this could be made to work automatically, but since I don't know Flash very well I don't know how to do this.
this.onEnterFrame = function() { var today:Date = new Date(); var currentYear = today.getFullYear(); var currentTime = today.getTime(); var currentMonth = today.getMonth(); var daysPerMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31); var targetDay = daysPerMonth[currentMonth]; var targetDate:Date = new Date(currentYear, currentMonth, targetDay); // etc. }March 20th, 2007 at 11:28 amThanks for your suggestion Drixer, did you try this out?
March 21st, 2007 at 3:34 amNo, I don’t have Flash installed so I’m just guessing that this will work. I think the only other thing that may be needed is a time parameter added to the targetDate so it counts down to 11:59pm prior to switching to the next month. The time most likely would need to be added after the targetDay parameter in the Date call. Let me know if it works out for you.
March 21st, 2007 at 10:55 amit works for me, but i would like the coundown to be able to count until specific hour with minutes example: till 1 july to 1 pm. i dont know actionscript so i cant modify it. and after that count up from the date. Any one can write the script for me?
April 15th, 2007 at 7:29 amWhat I have above should do what you want, the time can be added to the targetDate variable like this:
hour: An integer from 0 (midnight) to 23 (11 p.m.).
minute: An integer from 0 to 59. This parameter is optional.
second: An integer from 0 to 59. This parameter is optional.
millisecond: An integer from 0 to 999. This parameter is optional.
As far as counting to another date automatically that could be done also, but would need to have the data provided by you if the dates were not a specific distance apart. You could simply enter in the new date/time manually after the given target date is reached. I would write the script for you, but like I said I don’t have Flash installed so I wouldn’t be able to test it.
April 16th, 2007 at 6:34 amBTW - this doesn’t work perfectly. For some reason when I just used the tutorial as is the seconds only displayed a “0″ when they were less than 10. I changed sec.length
April 26th, 2007 at 3:39 pmFor some reason it didn’t post my whole comment…
April 26th, 2007 at 3:46 pmSorry I didn’t get back to you sooner, it seems the comments didn’t show up in the log as a new comment either. I will look into that problem. Since I didn’t see the rest of the comment I can’t say for sure what the problem is, but if only a zero is showing I would guess that the variable for seconds doesn’t contain any data. I am only guessing that is the problem, and assuming the section that adds the leading zero to the seconds is ok.
April 29th, 2007 at 12:35 amHow do I display an event after the count down has reached 0? Please help!
Thanks!
October 22nd, 2007 at 5:10 pm“How do I display an event after the count down has reached 0? Please help!
Thanks! ”
Some help on this issue would greatly be appreciated…
June 10th, 2008 at 10:07 am