Flash
  Home arrow Flash arrow Page 4 - Organizing Movie Clips in Flash MX
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

Organizing Movie Clips in Flash MX
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-02-01

    Table of Contents:
  • Organizing Movie Clips in Flash MX
  • Importing External Movies and Images
  • Movie and Instance Stacking Order
  • Stacks and Order of Execution

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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.

       · This article is an excerpt from the book "ActionScript for Flash MX: the Definitive...
     

    Buy this book now. This article 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). Check it out today at your favorite bookstore. Buy this book now.

    FLASH ARTICLES

    - Decorator Pattern
    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications
    - ActionScript in Flex Applications
    - A Closer Look at Apollo`s File System API
    - Using the File System API
    - ActionScript 101
    - Flash Buttons
    - Advanced Flash Animation
    - Creating Your First Animated Movie with Flas...
    - Flash: Building Blocks






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT