PDA

View Full Version : Countdown timer


abacajan
12-23-2005, 02:23 AM
Hey guys,
I thougtht i would try to make a timer to count down to christmas. Only to find out that this is incredibly hard. I eventually found out a way to do it but its a bit rough. It wont count down 12 months once i get past the 25th of december. But it will do the job fine from the 1st of january. What i would like to see is someone else try it. My script was fairly long and im sure there would be an easier way. What im looking for is a couple of dynamic textboxes for months, days, hours, minutes and seconds untill christmas. Lets say its the 5th of march
(my birthday). Instead of saying 9 months, 270 days (or whatever it might be) and so on, Im looking for 9 months, 26 days and so on. Good luck!

P.S ill post my swf and fla when i get enough response to this thread.

P.S.S
By the time people come accross this post itll probibly be past christmas and we will all be playing around with our new versions of flash 8! Yay!

See ya!

Billy T
12-23-2005, 02:43 AM
do you want to use the users system clock or something more reliable like a PHP date object?

Headshotz
12-28-2005, 01:54 AM
Well it is past christmas, but make one for new years :D

I almost have it, this is just a test version

//***********
//Another Code with pink
//***********
//Yay, a timer, now I can dance
createEmptyMovieClip("codeholder", 1);
codeholder.onEnterFrame = function() {
today = new Date();
seconds = Math.floor((newyears.getTime()-today.getTime())/1000);
minutes = Math.floor(seconds/60);
hours = Math.floor(minutes/60);
days = Math.floor(hours/24);
cday = days;
if (cday<10) {
cday = "0"+cday;
}
chour = hours%24;
if (chour<10) {
chour = "0"+chour;
}
cminute = minutes%60;
if (cminute<10) {
cminute = "0"+cminute;
}
csecond = seconds%60;
if (csecond<10) {
csecond = "0"+csecond;
}
input = cday+" "+chour+" "+cminute+" "+csecond;
//Just this part is wrong
newyears = new Date(2005, 29, 12, 24);
};


It doesnt quite work, by the way you have to draw the dynamic text box yourself and call it input :)

invader
01-03-2006, 07:04 PM
when posting code in forums, i usually try to make it 100% copy-and-paste-able. for the dynamic text field, you can just create it with createTextField, then add the text to it with .text=

that way, beginners can try out your script with little or no flash expertise required.

i like they script, btw.. i don't see too many people use modulo, and instead write a complex workaround for it.

Headshotz
01-05-2006, 03:55 AM
I found the code buried in one of my 1000's of unfinished flash files.

abacajan
01-06-2006, 09:06 PM
incredible how some people can do that just effortlessly with about 20 lines of code and mine took 7 hours and about 100 lines of code. sorry but i dont have my source code here with me right now. ill post it next saturday hopefully. (14/1/2006). By the way i used modulo in my script too to work out if it was a leap year like this:

myDate=new Date();
year=myDate.getFullYear;
if (year%4 !=0){
leapYear = false;
}
else if (year%4 = 0){
leapYear = true;
}

By the way i suppose thats what defines an amature from a pro,
I know i could have just done this:

myDate=new Date();
year=myDate.getFullYear;
if (year%4 !=0){
leapYear = false;
}
else{
leapYear = true;
}

but i find it easier to do it longer.
Ive also noticed pros do almost everything in variables for a game so its easier to change. but i have to go hunting!

Headshotz
01-07-2006, 01:22 AM
:eek:

100 lines for a countdown timer, I dont know where this code came from, I dont remember writing it. Maybe I got it off a website and was modifying it.

aaroncampbell
09-08-2006, 11:37 PM
I know this is more than a little late, but you do realize that technically we don't have a leap year every 4 years right? Technically it's:
All years divisible by 4, unless divisible by 100, unless divisible by 400.

So basically, 1996 IS because it's divisible by 4 and NOT 100. 1900 is NOT because although it is divisible by 4, it is ALSO divisble by 100. 2000 IS...it's divisible by 4 (so yes), but ALSO by 100 (so no), but then it IS divisble by 400 (so yes again). Check wikipedia http://en.wikipedia.org/wiki/Leap_year#Rules_for_determining_when_to_have_a_lea p_year

So, something more like this maybe:
if (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)) {
leapYear = true;
} else {
leapYear = false;
}