7.1. Referring to Movie Clips via ActionScript
Problem
You need to refer to a movie clip programmatically.
Solution
If you are creating the movie clip at authoring time, select the movie clip on stage and specify an instance name for it using the Property inspector. Then you can refer to it by that name via ActionScript.
Discussion
We saw in the Introduction how to refer to movie
clips throughout your ActionScript code. But what names should you
substitute for myMovieClip or
myNestedMovieClip in the earlier examples
to refer to your own movie clips?
The instance name you use in your code must match the name of the movie clip instance on stage, not the name of the Library symbol from which the clip is derived. Therefore, you must set the clip’s instance name using the Property inspector before you can refer to it from ActionScript (see Figure 1-4). For example, if you’ve set the instance name of a movie clip to “circle_mc” using the Property inspector, you can control it via ActionScript:
circle_mc._xscale = 200;
See Also
For information on working with runtime-generated movie clips, see Recipe 7.2, Recipe 7.18, and Recipe 7.19. Also refer to Recipe 3.1.
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