Referring to Instances and Main Movies

In the earlier sections, we learned how to create and layer movie clip instances and external .swf files in the Flash Player. We must be able to refer to that content in order to effectively control it with ActionScript.

We refer to instances and main movies under four general circumstances, when we want to:

  • Get or set a property of a clip or a movie

  • Create or invoke a method of a clip or a movie

  • Apply some function to a clip or a movie

  • Manipulate a clip or a movie as data, for example, by storing it in a variable or passing it as an argument to a function

While the circumstances under which we refer to clip instances and movies are fairly simple, the tools we have for making references are many and varied. We’ll spend the rest of this section exploring ActionScript’s instance- and movie-referencing tools.

Using Instance Names

Earlier, we learned that movie clips are referred to by their instance names. For example:

trace(myVariable);  // Refer to a variable
trace(myClip);      // Refer to a movie clip

In order to refer to an instance directly (as shown in the preceding trace( ) example), the instance must reside on the timeline to which our code is attached. For example, if we have an instance named clouds placed on the main timeline of a document, we may refer to clouds from code attached to the main timeline as follows:

// Set a property of the instance clouds._alpha = 60; // Invoke a method on the instance clouds.play( ); // Place the instance in an array ...

Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.