Hide Header Hide Menu                       Designed for 800 x 600 minimum screen resolution

To: Home @ Godsafe.net - Image: Godsafe.net Logo Image: Godsafe.net Banner - a composite image of Sir John Godsalve, Black Spot Games, Water Art and Coumarin under a microscope


Show Current Date

I've managed to find some time to have another look at Flash and have been working through the excellent Flash tutorials at Flasherdotorg.
As an extension to their Display Current Date and Time tutorial I have produced a movie that breaks up the date constituents so that they can be reused.

Download the flash file and explore the code yourself or view our completed movie.

Note: The instructions below are for Flash MX and earlier, later versions of Flash will require stricter variable typing.


The instructions for reproducing this yourself are identical to Flasherdotorg's tutorial, up until the final stage and instead of typing the following in the Actions panel:

message = todayIs;

we first type:

At line 7 we create 2 new variables dayIs and dayName.
At line 8 we use the todayIs variable to get at the day element of the date and set this as the value of the variable dayIs.
However, this is held as an integer value between 0 and 6.

At line 12 we introduce a switch statement which we use on lines 14-34 to set a value to our variable dayName (which is the word equivalent of the day of the week integer we set in dayIs at line 8).
The switch statement simply looks at the value of dayIs and when it finds the case that matches that value it sets dayName to the value corresponding to that case.
The break statement tells the code to leave the switch loop once it has found the right case.

Top


next we type:

At line 37 we start to add text to our message. We could do this with all the date constituents at the final stage but this way it is easier to see what is happening at each stage.
At line 40 we add the dayName value to the text already in our message and place a space at the end of the message so that the next part of the date doesn't get fused with our day of the week value.
Press CTRL + ENTER to see what is output at this stage.


next we type:

At line 43 we have added a new variable called dateIs which will hold the date of the month.
At line 44 we set dateIs with the date constituent of todayIs.
At line 47 we add the date to our message.
Press CTRL + ENTER to see what is output at this stage.

Top


next we type:

At line 50 we create 2 new variables monthIs and monthName.
At line 51 we use the todayIs variable to get at the month element of the date and set this as the value of the variable monthIs.
However, this is held as an integer value between 0 and 11.


next we type:

At line 55 we start a switch statement similar to the one at line 12 but instead based on the integer value of monthIs and setting the word equivalent of the month to the variable monthName (created at line 50).

Top


next we type:

At line 95 we add our month name (and another space) to the message.
Press CTRL + ENTER to see what is output at this stage.


finally we type:

At line 98 we add a new variable yearIs to hold our year value.
At line 99 we set yearIs to the year value derived from the year part of todayIs and using the command getFullYear.
Note: if we use the command getYear our output would be the year - 1900.
Finally, we add the Year to our message.
Press CTRL + ENTER to see what is output at this stage or scroll down to see the completed flash movie.



Top