Graphics Programs Reference
In-Depth Information
An onEnterFrame handler in line 4 will be needed so that we will be able to see the
rotation. Line 7 checks to see whether the Right Arrow key is pressed. If it is, the angle
is updated by 2 degrees, which will result in a clockwise rotation. In line 8, a similar
test checks to see whether the Left Arrow key is pressed. If so, the angle is decreased
by 2 degrees for a counterclockwise rotation.
Next, the rotations of the steering wheel and the car movie clips are set to the new
value of the angle in lines 11 and 12. Note that visually, it appears that the steer-
ing wheel and the car are rotating at different angles. This is only an illusion since the
steering wheel was designed with the ball at the top as its initial position and the car
was designed to be pointing to the right as its initial position.
// initialze the starting angle
angleInDegrees = 0;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
this.onEnterFrame = function()
{
// check the arrow keys to change the angle
if ( Key.isDown(Key.RIGHT)){ angleInDegrees += 2;}
if ( Key.isDown(Key.LEFT) ){ angleInDegrees -= 2;}
// rotate the steering wheel and car
wheel_mc._rotation = angleInDegrees;
car_mc._rotation = angleInDegrees;
// get the angle in radians
angleInRadians = angleInDegrees * Math.PI/180;
// display the angle info
degrees_txt.text = angleInDegrees;
radians_txt.text = angleInRadians;
};
Figure 5.9 Script for the radian calculator
In line 15, the rotation angle is converted from degrees to radians using the formula
from Figure 5.7. Finally, the current value of the angle in both degrees and radians is
displayed by setting it to the text of the dynamic text fields, degrees_txt in line 18
and radians_txt in line 19.
Search WWH ::




Custom Search