Graphics Programs Reference
In-Depth Information
Step 4: Create the motion
We are now ready to create the circular motion. To do this, we will use an onEnterFrame
handler so that we can keep looping on the frame and update the angle each time.
17
18
19
20
21
22
23
// set up the frame loop
this.onEnterFrame = function()
{
angle += 5; // update the angle
setObject(); // move the object
}
Notice the use of the expression this.onEnterFrame . Here this refers to the root
Timeline. The statement angle += 5 is used to increase the angle by 5 degrees each
time the frame is entered.
Save your movie as 5_1_roulette1.fla and test it. You should see the ball rotating
clockwise around the roulette wheel. You can speed up the motion by simply changing
the angle update to a larger number such as 10.
Tip: Verify that you can rotate the ball counterclockwise by using any one of the follow-
ing three changes:
angle -= 5
object_mc._y = yc - r * Math.sin(a)
object_mc._x = xc - r * Math.cos(a)
Step 5: Add the wheel rotation
Now that the ball is moving, let's make the wheel rotate in the opposite direction. The
registration point of the wheel is centered on the object and located at the middle of
the Stage. Although we could rotate the wheel at a different speed than the ball, it is
easy and convenient to simply use the opposite angle of rotation of the ball. This can
be done by inserting a single line of code in line 22 as shown here.
19
20
21
22
23
{
angle += 5; // update the angle
setObject(); // move the object
wheel_mc._rotation = -angle; // rotate wheel
}
 
Search WWH ::




Custom Search