
Page 2 of 2
Jono Hayward
This user is yet to take control of their account and provide a biography. If you are the author of this article, please contact us via support AT actionscript DOT org.
View all articles by Jono HaywardIf however you want to leave the months as numbers, instead of that massive load of if statements, simply write this code:
month = month + 1;
We add one to the month again because January is zero etc. For this we dont need the "day" variable because it tells you how far into the week you are...Not really what you usually see in a numbers-only date.
step five(c):
>> to make the minutes and seconds display correctly, we again use an if statement.
if (minutes<10) {
minutes = "0"+minutes;
}
if (seconds<10) {
seconds = "0"+seconds;
}
This is slightly more complex. It says to the program, "If the value of minutes is less than 10, then add a zero on the front". This is a slighly odd type of adding - its the type where if you add 5 and 3 you get 53, not 8. That works because the 0 we add on is in speech marks "" so that makes it a string. For more info see the Variables 101 tutorial (linked below in "Related Articles").
step six:
To change the time from 24 hour to 12 hour, we use this code (if you want it on 24 hour time then just skip this):
if (hours>12 ) {
hours = hours-12;
ampm = "PM";
} else if (hours == 12) {
ampm = "PM";
} else {
ampm = "AM";
}
if (hours == 0) {
hours = 12;
}
What this does is say to the program, "If the value of hours is over 12, then subtract 12 from it" and then change the status of the am/pm indicator to PM.
It then counters for the fact that if the hours is actually 12 and it becomes 0, it changes the hours to 12 so midnight doesn't become 0AM.
step seven:
Here's where it gets interesting. This is where we put together what will go into the text boxes.
Use this code to put together the time (12 hours):
time = ((hours) + ":" + (minutes) + ":" + (seconds) + " " + (ampm));
Or this code to put together the time (24 hours):
time = ((hours) + ":" + (minutes) + ":" + (seconds));
Basically what this does is put together a string of the time - so you get the hours, then a ":" then the minutes and so on.
use this code to put together the date (with names):
datefinal = ((day) + " " + (date) + " " + (month) + " " + (year));
Same concept basically, you get the day then it puts a space in then the date etc
Use this code to put together the date (using numbers only, if you use this remember to perform step five(b) and not (a)):
datefinal = ((date) + "/" + (month) + "/" + (year));
Same concept, please note that this is in australian date format, to make it american simply switch around the "date" and "month" variables.
Thats it! Just hit ctrl/apple + enter to test your movie.
*This how the clock updates itself. Instead of doing anything big and complex the way this works is it runs 12 times every second (or however fast the framerate of the movie is set to) and every time it gets to frame 1 it checks the system clock again. This means that when the seconds change it will "catch" it and change itself.
Spread The Word
Related Articles
3 Responses to "Simple digital clock" 
|
said this on 27 Mar 2007 10:54:16 AM CDT
Neat! The only thing I would add is to use the Switch() statement instead of those multiple if/else statements when finding day and month.
|
|
said this on 29 May 2007 9:39:14 AM CDT
Nice little script, but details count such as using the var keyword and missing the .text on the text fields could mean the difference between the script working & not working especially when you are saying to copy and paste your code.
|
|
said this on 19 Oct 2007 1:58:19 PM CDT
I was a good tutorial but you need to be more specific. I tried making this and I've never done anything before in flash. I got all the scripting right just it was apparently in the wrong spot my teacher fixed it for me anyways you need to tell people that the scripting needs to be within the Clock movie!
|



Author/Admin)