O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required