_rotation

Next let's rotate the Movie Clips around the center point using the _rotation property. Rotation is described as a number with 0 being no rotation and 360 one full rotation (there are 360 degrees in a circle). Of course _rotation can be a much larger number, or even a negative number, but we'll get to that in a later exercise. For now, let's start easy by turning all of these clips upside down, or rotating 180 degrees.

Remember, we use set variable to dynamically set MovieClip properties like _x, _y, _alpha and now _rotation

Let's give this a little test by rotating line 180 degrees:

Check it out. The clips should all be upside down:

Now let's space all of these clips evenly using some simple math. Think about this problem for a moment: There are 360 degrees in a circle and we have 30 objects. 360/30 is 12, so each new Movie Clip needs to rotate 12 degrees farther than the last. Can you build an equation to make this happen? I'll give you a hint - use that variable n, since it's incrementing with every loop.

There are several strategies you can employ to accomplish this task, but I'm going to focus on one. Since we have the variable n incrementing by 1 at the end of every loop, we can multiply times 12 (the amount we want eavh new clip to rotate). See what happens if we multiple 360/30 times n for the first five loops:

360/30
* n =
_rotation
12
* 0 =
0
12
* 1 =
12
12
* 2 =
24
12
* 3 =
36
12
* 4 =
48

Looks like the math is going to work out. Now just change the Value from 180 to 360/30*n:

Remember that we should be working toward ActionScripts projects that are easy to customize later. This generally means using variables whenever possible, and declaring those variables at the start of the script. Instead of digging around the script when you want change the number of lines, let's use a variable called numLines:

  1. At the very start of the script, use var to set numLines = 30 and change the data Type to Number
  2. Change n<30 to n<numLines
  3. Change the numerator in the _rotation calculation from 30 to numLines

Does your project still work? Change the numLines variable to 80 and make sure the lines are still spaced evenly: