Graphics Programs Reference
In-Depth Information
We could do the same calculation for the minute hand. Note, however, that when we
do this we have to wait one complete minute before the minute hand moves. With nor-
mal clocks, the minute hand moves slowly and continuously as the minute progresses.
To have that effect, we need to include the additional fraction of a minute given by the
term
mySecond/60
in line 25.
The hour hand is handled in a similar way. Since there are 12 hours and 360 degrees,
we need to multiply the number of hours by 30 to get the correct rotation. As above,
when we do this we have to wait one complete hour before the hour hand moves. With
normal clocks, the hour hand moves slowly as the hour progresses. To have continuous
movement of the hour hand, we need the additional term provided in line 26.
20
21
22
23
24
25
26
27
28
// define the frame loop actions
this.onEnterFrame = function()
{
getTime();
seconds_mc._rotation = mySecond * 6;
minutes_mc._rotation = (myMinute + mySecond/60) * 6;
hours_mc._rotation = myHour * 30 + (myMinute/60) * 30;
}
Step 5: Define the pendulum actions
The last step is to define the behavior of the pendulum itself. We are instructing the
user to click on the pendulum to set it in motion, so we need an
onRelease
handler.
Once the user clicks on the pendulum, we need to store the current time in a vari-
able
startTime
, since we will be stopping the pendulum movement after 30 seconds.
In order to see the pendulum motion, we need to provide an
onEnterFrame
handler.
However, since we're dealing here with pendulum actions, it is convenient to place it
inside the
onRelease
handler.
29
30
31
32
33
34
// define the pendulum actions
pendulum_mc.onRelease = function()
{
startTime = mySecond;
pendulum_mc.onEnterFrame = function()
{
Search WWH ::
Custom Search