4.14. Changing a Movie Clip’s Location at Runtime with ActionScript
Problem
You want to relocate an element at runtime, through scripting.
Solution
Set a movie clip or button’s _x and _y properties with ActionScript.
Discussion
By default, when you position an element on the stage, it appears in the same location on the output .swf movie. However, it is possible to set the positioning at runtime by using ActionScript. ActionScript can see only certain kinds of elements in a movie. In order to control an element with ActionScript, it must be an object, which means it must be a movie clip, button, or dynamic or input text field. ActionScript cannot control draw vector art, graphic symbols, or imported bitmaps, unless they are enclosed in a movie clip or button.
Tip
In addition to the list specified in the preceding paragraph, Action-Script can control components and video objects.
In addition, for ActionScript to see one of these graphic elements, the element must have a unique identifier. You can give a movie clip, button, dynamic or input text field a unique identifier by selecting it and giving it an instance name in the Property inspector. After you specify a name for the object, you can address it using ActionScript.
You can control these objects through ActionScript using built-in events, properties, and methods:
- Events
Events refer to changes in the environment that the object is aware of. For example, a button is aware when it is pressed.
- Properties
Properties describe the object. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access