Understanding ActionScript > About scripting in ActionScript > About the MovieClip object
About the MovieClip object
ActionScript's predefined classes are called objects. Each object allows you to access a certain type of information. For example, the Date object has methods (for example, getFullYear
, getMonth)
, that allow you to read information from the system clock. The Sound object has methods (for example, setVolume
, setPan
) that allow you to control a sound in a movie. The MovieClip object has methods that allow you to control movie clip instances (for example, play
, stop
, and getURL
) and get and set information about their properties (for example, _alpha
, _framesloaded
, _visible
).
Movie clips are the most important objects of a Flash movie because they have Timelines that run independently of each other. For example, if the main Timeline only has one frame and a movie clip in that frame has ten frames, each frame in the movie clip will still play. This allows instances to act as autonomous objects that can communicate with each other.
Movie clip instances each have a unique instance name so that you can target them with an action. For example, you may have multiple instances on the Stage (for example, leftClip
and rightClip
) and only want one to play at a time. To assign an action that tells one particular instance to play, you need to use its name. In the following example, the movie clip's name is leftClip
:
leftClip.play();
Instance names also allow you to duplicate, remove, and drag movie clips while a movie plays. The following example duplicates the instance cartItem
to fill out a shopping cart with the number of items purchased:
onClipEvent(load) { do { duplicateMovieClip("cartItem", "cartItem" + i, i); i = i + 1; } while (i <= numberItemsPur); }
Movie clips have properties whose values you can set and retrieve dynamically with ActionScript. Changing and reading these properties can change the appearance and identity of a movie clip and is the key to creating interactivity. For example, the following script uses the setProperty
action to set the transparency (alpha setting) of the navigationBar
instance to 10:
setProperty("navigationBar", _alpha, 10);
For more information about other types of objects, see Using predefined objects.