Graphics Programs Reference
In-Depth Information
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// create the motion along the circular path
this.onEnterFrame = function()
{
// update the angle increment based on _xmouse
if (_xmouse > xo ) {angle += 4; }
else angle -= 4;
// loop over all the objects
for (var i:Number i = 0; i < numberOfObjects; i++)
{
thisObj = this["object"+i];
placeObj(thisObj,i);
displayObj(thisObj)}
}
}
A Little More User Interaction
Instead of having only uniform clockwise or counterclockwise motion, let's look at the
situation where we want to have the motion gradually slow down as the user moves the
cursor toward the center of the objects and speed up as the cursor moves away from
the center toward the outside of the Stage. A typical application might be where we
want the user to click on the objects for additional information. We can do this by modi-
fying the test we have for the horizontal position of the cursor.
Exercise 6.5: Variable Speed of Rotation
Open 6_5_xzRotation2.fla. We'll use this as a starting point for setting up the vari-
able speed of rotation. We are going to create a relationship between the horizontal
speed of the cursor and the speed with which the objects rotate in a circle.
Step 1: Define the angle change
Let's define the variable angleChange , which is a measure of how far the horizontal
position of the cursor is from the center of the Stage, which we have previously defined
as xo . We'll need to place this inside the onEnterFrame handler. First, we'll calculate
how far the horizontal location of the cursor is from the center of the Stage using
_xmouse-xo . We'll round the number off and store it in angleChange . Then we use this
to update startAngle, which controls the motion. Modify lines 67 through 69 in the
script to those shown here.
Search WWH ::




Custom Search