Graphics Programs Reference
In-Depth Information
can use in a frame loop to constantly update the current time. Since Flash provides
time with a 24-hour rather than a 12-hour clock, we'll define a variable ampm and set it
initially to "am" in line 8. Next we define a new object called newDate by invoking the
built-in Date object in line 9 that provides information from the system clock as proper-
ties of the object.
To set the hour of the day, we'll define a variable myHour and use the getHours()
property in line 10 to extract the hour. Since we are on 24-hour clock time, we need a
couple of tests to convert to U.S. 12-hour timekeeping. If the hour is 12 or greater than
12, we are in the afternoon or evening, and so we will then set ampm to "pm" (lines 11
and 13). Also, since we want only hours that are less than or equal to 12, we will sub-
tract 12 from anything greater than 12 (line 14). Extracting the number of minutes and
seconds is straightforward and given in lines 16 and 17.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function getTime()
{
// script to extract the time from the newDate object
ampm = "am";
newDate = new Date();
myHour = newDate.getHours();
if (myHour > 11)
{
ampm = "pm";
if (myHour > 12) { myHour = myHour - 12;}
}
myMinute = newDate.getMinutes();
mySecond = newDate.getSeconds();
};
Step 4: Define the frame loop actions
Inside the frame loop, we want the clock to keep time and show the correct position of
the second, minute, and hour hands. Each time through the loop, we will issue a call to
the getTime() function in line 23. From there we need to convert to the proper angle
of rotation for each of the three hands. Since there are 60 seconds in a minute and the
second hand must rotate 360 degrees in a minute, then the second hand must rotate
six degrees for each second. So we just need to multiply the number of seconds by 6 to
get the correct rotation of the second hand as given in line 24.
Search WWH ::




Custom Search