Home arrow Flash arrow Page 4 - Organizing Movie Clips in Flash MX
FLASH

Organizing Movie Clips in Flash MX


Continuing our discussion of Flash, in this article you'll learn how to import external movies and images, add identifiers to movie clips, and more. This article, the second of four parts, is excerpted from chapter 13 of the book ActionScript for Flash MX: the Definitive Guide, second edition, written by Colin Moock (O'Reilly; ISBN: 059600396X). Copyright © 2005 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 5 stars5 stars5 stars5 stars5 stars / 4
February 01, 2007
TABLE OF CONTENTS:
  1. · Organizing Movie Clips in Flash MX
  2. · Importing External Movies and Images
  3. · Movie and Instance Stacking Order
  4. · Stacks and Order of Execution

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Organizing Movie Clips in Flash MX - Stacks and Order of Execution
(Page 4 of 4 )

The layering of movie clips and timeline layers affects code execution order. The rules are as follows:

  • Code on frames in different timeline layers always executes from top to bottom (relative to the timeline panel).
  • When manually created instances are initially loaded, code in their timeline and onLoad() event handlers executes according to the Load Order set in the Publish Settings of a Flash document—either Bottom Up, which is the default, or Top Down.

    For example, suppose we have a timeline with two layers, top and bottom, where top is above bottom in the layer stack. We place clipX on layer top and clipY on layer bottom. If the Load Order of the document is set to Bottom Up, then the code in clipYwill execute before the code in clipX. If, on the other hand, the Load Order of the document is set to Top Down, then the code in clipXwill execute before the code in clipY. This execution order applies only to the frame on whichX andY appear for the first time.
  • Once loaded, all instances of a movie are added to an execution order, which is the reverse of the load order; the last instance added to the movie is always the first to have its code executed.

Use caution when relying on these rules. Layers are mutable, so you should avoid producing code that relies on their relative position. Strive to create code that executes safely without relying on the execution order of the clips in the stack. We can avoid some of the issues presented by the execution stack by keeping all our code on a scripts layer at the top of each code-bearing timeline.

Referring to Instances and Main Movies

In earlier sections of this chapter, we saw 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 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 saw that movie clips are referred to by their instance names. For example:

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

  trace(someVariable);   // Refer to a variable
  trace(someClip_mc);    // 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 namedclouds_mcplaced on the main timeline of a document, we can refer toclouds_mcfrom code attached to the main timeline, as follows:

  // Set a property of the instance
  clouds_mc._alpha = 60;
  // Invoke a method on the instance
  clouds_mc.play();
  // Place the instance in an array of other related instances
  var background = [clouds_mc, sky_mc, mountains_mc];

If the instance we want to reference does not reside on the same timeline as our code, we must use a more elaborate syntax, as described later in this section under “Referring to Nested Instances.”

Please check back next week for the continuation of this article.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
FLASH ARTICLES

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials