Sunday, 25 May 2008

Display time

This flash tutorial will teach you how to display the time. The time function is taken directly from the system clock. This tutorial requires action scripts.

Time

Step 1

Create a new flash document.
Using the dynamic text tool drag a rectangle shapes on the stage like below:

Step 2

Using the selecting tool (v) select the dynamic text box. And then give it a variable name. eg. theTime.

Step 3

Convert the dynamic text box into a movie clip by selecting F8, choose an appropriate name and click ok.

Step 4

Now right click on your movie clip and select actions.

Add the following code:

onClipEvent (enterFrame) {
myTime = new Date();
theSeconds = myTime.getSeconds();
theMinutes = myTime.getMinutes();
theHours = myTime.getHours();

if (theHours>=12) {

ampm = "pm";

} else {
ampm = "am";
}

if (theHours>=13) {
nHours = nHours-12;
}

if (length(theMinutes) == 1) {
theMinutes = "0" +theMinutes;

}

if (length(theSeconds) == 1) {
theSeconds = "0"+theSeconds;
}

theTime = theHours+":"+theMinutes+":"+theSeconds+" " +ampm;
}

Step 5

Test your movie Ctrl + Enter.


You should now have a time display.

0 comments:

What next ?

Subscribe to Flash Tutorials

Add to Technorati Favorites

Follow my Twitter