Written by: Jono Hayward, www.groove.org.au,
Difficulty Level: Beginner
Requirements: Flash MX 2004 or higher
Assumed Knowledge: Variables

Download FLA

Clock tutorial
This is a pretty simple clock
I find it easiest to put all this in a movie clip, then you can move your clock around the stage wherever you want it. So basically:

step one:

Hit ctrl/apple + f8 to create a new movie clip. Doesn't matter what you call it. Open the library by pressing ctrl/apple + L and drag the clip onto the stage.

step two:
Open the clip by double-clicking it in the library. Right/control click on the second frame of the clip and click "insert frame"*.

step three:
Inside the movie clip make two dynamic text boxes. Give one a variable name of "time" (without the speech marks) and one a variable name of "datefinal".

step four:
Click on the first frame of the movie and open the actions panel. This is where the fun begins.
First we want to get all the values off of the user's system clock and assign them to separate variables.
Copy this code into the actions panel:

mydate = new Date();
seconds = mydate.getSeconds();
minutes = mydate.getMinutes();
hours = mydate.getHours();
day = mydate.getDay();
date = mydate.getDate();
month = mydate.getMonth();
year = mydate.getFullYear();

step five:
How some of these variables, if we just shoot them off to the text box will give some odd results. For example, if it's Sunday the "day" variable will just return "0", if its Monday it will return "1" etc. Same with months. And while a conventional digital clock would display the time as 9:03:05 this would show 9:3:5 which just looks weird. So to fix all this, we use these bits of code:

step five(a):
>>to change the day to its name, we use an if statement.

if (day==0){
        day = "Sunday"
} else if (day==1){
        day = "Monday"
} else if (day==2){
        day = "Tuesday"
} else if (day==3){
        day = "Wednesday"
} else if (day==4){
        day = "Thursday"
} else if (day==5){
        day = "Friday"
} else if (day==6){
        day = "Saturday"
}

What this basically does is say to the program, "if the day is 0 then the day is actually sunday" and so on.

Same concept for months

if (month==0){
        month = "January"
} else if (month==1){
        month = "February"
} else if (month==2){
        month = "March"
} else if (month==3){
        month = "April"
} else if (month==4){
        month = "May"
} else if (month==5){
        month = "June"
} else if (month==6){
        month = "July"
} else if (month==7){
        month = "August"
} else if (month==8){
        month = "September"
} else if (month==9){
        month = "October"
} else if (month==10){
        month = "November"
} else if (month==11){
        month = "December"
}