- ActionScript Elements Used to Make Games and Toys
- Lesson 15: Controlling the Playback of a Movie Clip
- Lesson 16: Controlling the Properties of a Movie Clip
- Lesson 17: Dragging and Dropping Movie Clips
- Lesson 18: Movie Clips and Levels
- Lesson 19: Duplicating Movie Clips
- Lesson 20: Controlling Multiple Movie Clips
- Lesson 21: Detecting Collisions
- Lesson 22: Using Movie Clips to Change What Is on the Screen
- Lesson 23: Accepting Keyboard Input
- Lesson 24: Playing Sounds
Lesson 16: Controlling the Properties of a Movie Clip
Example file: Mcproperties.fla
In addition to controlling the insides of a movie clip, you can also control its external properties. For instance, you can control a movie clip's position, its rotation, and its scale.
The example movie Mcproperties.fla contains a sample movie clip of a fox in the middle of the screen. Both the library fox and the movie clip instance are named "fox."
In addition, there are eight buttons around the box. Each of these buttons sets a movie clip property of the fox. You can see how this screen appears in Figure 3.3. The first three are labeled "Left," "Middle," and "Right."
Figure 3.3 The fox movie clip in the center can be repositioned, scaled, and rotated by the buttons around it.
In "Lesson 6: Animating with ActionScript," in Chapter 2, you saw that the _x property of a movie clip can be used to set its horizontal location on the Stage. This is what the "Left," "Middle," and "Right" buttons will use. They could also use the _y property to set the vertical location of the movie clip, but that isn't needed in this example. Here is the code from the "Left" button. It sets the horizontal location of the fox to 200, which is slightly to the left of center, considering that the movie is 550 pixels wide. The "Middle" and "Right" buttons only differ in the value to which the _x property is set.
on (press) { fox._x = 200; }
To scale a movie clip, you need to use the _xscale and _yscale properties. If these are set to the same value, they provide a way to uniformly scale a movie clip. A value of 100 stands for 100% scale.
TIP
You can also change only _xscale or _yscale individually, or set them to different values to make a movie clip thinner or flatter.
Here is the button script for the "50%" button. The other two scaling buttons use the same code, but with a different value.
on (press) { fox._xscale = 50; fox._yscale = 50; }
To rotate a movie clip, you need to use the _rotation property. It takes a value in degrees, so 0 is the same as 360. You can go higher than 360 or lower than 0, but Flash just interprets that into a reading between 0 and 360.
Here is the script for the "Tilt" button. It rotates the movie clip 30° clockwise. The "Straight" button just sets the rotation back to 0.
on (press) { fox._rotation = 30; }
By using these properties in more complex code to come later in this book, you'll be able to move movie clips around the Stage to create all sorts of games.