Flash
  Home arrow Flash arrow Page 2 - Fun Things to Do with Movie Clips in Flash...
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

Fun Things to Do with Movie Clips in Flash MX
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 21
    2007-02-15

    Table of Contents:
  • Fun Things to Do with Movie Clips in Flash MX
  • Method Versus Global Function Overlap Issues
  • Drawing in a Movie Clip at Runtime
  • Using Movie Clips as Buttons
  • Input Focus and Movie Clips
  • Building a Clock with Clips

  • 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


    Fun Things to Do with Movie Clips in Flash MX - Method Versus Global Function Overlap Issues


    (Page 2 of 6 )

    As we’ve mentioned several times during this chapter, some movie clip methods have the same name as equivalent global functions. You can see this for yourself in the Flash authoring tool. Open the Actions panel, make sure you’re in Expert Mode, and then take a look in the Actions folder under Movie Control and Movie Clip Control. You’ll see a list of Actions, including gotoAndPlay(), gotoAndStop(), nextFrame(), and unloadMovie(). These Actions are also available as movie clip methods. The duplication is not purely a matter of categorization; the Actions are global functions, fully distinct from the corresponding movie clip methods.

    So, when we execute:

      theClip.gotoAndPlay(5);

    we’re accessing the movie clip method named gotoAndPlay(). But when we execute:

      gotoAndPlay(5);

    we’re accessing the global function called gotoAndPlay(). These two commands have the same name, but they are not the same thing. The gotoAndPlay() global function operates on the current instance or movie. The gotoAndPlay() method operates on the clip object through which it is invoked. Most of the time, this subtle difference is of no consequence. But for some overlapping method/function pairs, this difference is potentially quite vexing.

    Some global functions require atarget  parameter that specifies the clip on which the function should operate. Thistarget  parameter is not required by the comparable clip methods because the methods automatically operate on the clips through which they are invoked. For example, in its method form, unloadMovie() works like this:

      theClip.unloadMovie();

    As a method, unloadMovie() is invoked without parameters, and it automatically affectstheClip. But in its global function form, unloadMovie() works like this:

      unloadMovie(target);

    The global function version of unloadMovie() requirestarget as a parameter that specifies which movie to unload. Why should this be a problem? Well, the first reason is that we may mistakenly expect to be able to unload the current document by using the global version of unloadMovie() without any parameters, as we’d use gotoAndPlay() without parameters:

      unloadMovie();

    This format does not unload the current clip. It causes a “Wrong number of parameters” error. The second reason thattarget  parameters in global functions can cause problems is a little more complex and can be quite a pain to track down if you’re not expecting it. To supply atarget  clip to a global function that requires atarget  parameter, we can use either a string, which expresses the path to the clip we wish to affect, or a clip reference. For example:

      unloadMovie(_level1);    // Target clip is a reference
      unloadMovie("_level1");  // Target clip is a string

    We can use a reference simply because references to clip objects are converted to movie clip paths when used in a string context. This is simple enough, but if thetarget  parameter resolves to an empty string or anundefinedvalue, the function operates on the current timeline!

    These examples demonstrate how an incorrect target clip reference can unintentionally unload the current timeline:

      unloadMovie(x);      // If x doesn't exist, x yields undefined, so
                           // the function operates on the current timeline
      unloadMovie("");     // The target is the empty string, so the function operates
                          
    // on the current timeline

    This can cause some quite unexpected results. Consider what happens if we refer to a level that doesn’t exist:

      unloadMovie(_level1);

    If_level1is empty, the interpreter resolves the reference as though it were an undeclared variable. This yieldsundefined, so the function operates on the current timeline, not_level1! So, how do we accommodate this behavior? There are a few options. We can check for the existence of our target before executing a function on it:

      if (_level1) {
       
    unloadMovie(_level1);
      }

    Or, we can choose to always use a string to indicate the path to our target. If the path specified in our string does not resolve to a real clip, the function fails silently:

      unloadMovie("_level1");

    In some cases, we can use the equivalent numeric function for our operation:

      unloadMovieNum(1);

    Finally, we can choose to avoid the issue altogether by always using clip methods:

      _level1.unloadMovie();

    For reference, here are the troublemakers (the ActionScript global functions that taketargetparameters):

      duplicateMovieClip()

      loadMovie()

      loadVariables()

      print( )

      printAsBitmap()

      removeMovieClip()

      startDrag()

      unloadMovie()

    If you’re experiencing unexplained problems in a movie, you may want to check this list to see if you’re misusing a global function. When passing a clip reference as atarget parameter, be sure to double-check your syntax.

    More Flash Articles
    More By O'Reilly Media


       · 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