Controlling Movie Clip Properties with ActionScript 3.0
- Changing a Property Value
- Changing Position
- Increasing or Decreasing a Property's Value
Most Flash designers are used to working with movie clip symbols in the Flash interface. But nearly all the features that can be accomplished with movie clips in the Flash interface can also be controlled with ActionScript. You can even create new movie clips from scratch with ActionScript. This article shows how to change some basic MovieClip properties with ActionScript.
Changing a Property Value
The basic syntax to change any property of a MovieClip is to type the clip's instance name, followed by a period (.), the property name that you want to change, an equals sign (=), and then the new value:
movieClipInstanceName.propertyName = value;
For example, if you have a MovieClip with an instance name of clip1 and you want to rotate it 90 degrees, the code would read this way:
Clip1.rotation = 90;
If you know the possible properties that you can control and their range of values, this simple technique can accomplish quite a bit.
The following table contains a few of the most common properties and their ranges. For the full range of properties and values, see Flash CS4 Help.
Property |
Values |
Description |
x |
–infinity to +infinity |
Horizontal position |
y |
–infinity to +infinity |
Vertical position |
rotation |
–180 to 180 (degrees) |
Rotation |
alpha |
0 to 1 (0 = transparent, 1 = opaque) |
Transparency |
scaleX |
–infinity to +infinity |
Horizontal scale |
scaleY |
–infinity to +infinity |
Vertical scale |
visible |
true (visible) or false (invisible) |
Visibility |
The Flash stage is measured from the upper-left corner. A movie clip with an x position of 0 means that the registration point of the clip is on the exact left of the stage. A position of 0 for the y value means that the clip is at the top of the stage. Values greater than zero for x and y refer to positions to the right and down, respectively. Negative x and y values indicate positions offstage to the left and above the stage.