Graphics Programs Reference
In-Depth Information
As with the 2D rotation we will need to define the number of objects to create (line 15)
and calculate the angle between any two objects on the circular path (line 19). In our
case with eight objects, circleAngle is 360/8 or 45 degrees.
The objects we need are created with a simple for loop that duplicates the object_mc
movie clip the specified number of times (lines 22-25).
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// set the number of objects to be created and startAngle
var numberOfObjects:Number = 8;
var startAngle:Number = 0; // starting angle on the circle
// calclate the angle between any 2 objects on a circle
var circleAngle:Number = 360/numberOfObjects;
// create the objects for the circular motion
for (var i:Number = 0; i < numberOfObjects; i++)
{
object_mc.duplicateMovieClip(“object”+i, i);
}
// place the object on the path of motion
function placeObj(thisObj,i)
{
// calculate the angle of the object
var myAngle:Number = i * circleAngle + startAngle;
var a:Number = myAngle * Math.PI/180; // in radians
Since we now have multiple objects, the placeObj function needs the addition of calcu-
lating the angle myAngle at which each object is on the path (line 31). At the beginning
when startAngle = 0 , the calculation for myAngle takes on the values i*circleAngle
or 0, 45, 90, ..., and 315 degrees respectively. The angles are then converted to radi-
ans in line 32.
The displayObj function is exactly as in the previous example, so let's go to where the
motion occurs in the onEnterFrame handler. All we need to add is a loop over all of the
objects (line 72), set thisObj to the current object (line 74), and then make calls to
the place and display functions.
Search WWH ::




Custom Search