Flash
  Home arrow Flash arrow Page 2 - Making Movie Clips Perform 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

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

    Table of Contents:
  • Making Movie Clips Perform in Flash MX
  • The MovieClip Class
  • Creating Movie Clips
  • Creating Instances

  • 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


    Making Movie Clips Perform in Flash MX - The MovieClip Class


    (Page 2 of 4 )

    All individual movie clips are instances of the MovieClip class, which defines the properties, methods, and event handlers supported by movie clips. The MovieClip class can be manipulated like other built-in classes; we can overwrite its methods or add new methods to it using the techniques we studied in Chapter 12. For example, the following code adds a new method, getArea(), to all movie clips:

      MovieClip.prototype.getArea = function () {
        return this._width * this._height;
      };

    As we’ll see in Chapter 14, as of Flash MX, the MovieClip class can even be used as the superclass for new classes (i.e., new subclasses can be derived from the MovieClip class). For full coverage of every property, method, and event handler supported by the MovieClip class, see the Language Reference.

    Types of Movie Clips

    Not all movie clips are created equal. In fact, there are three distinct types of clip available in Flash:

    1. Main movies
    2. Regular movie clips
    3. Components (formerly known as Smart Clips in Flash 5)

    In addition to these three official varieties, we can distinguish four subcategories of regular movie clips:

    1. Process clips
    2. Script clips
    3. Linked clips
    4. Seed clips

    While these unofficial subcategories are not formal terms used in ActionScript, they provide a useful way to think about programming with movie clips. Let’s take a closer look at each movie clip type.

    Main Movies

    The main movie of a Flash document is the main timeline and Stage present in every .swf document. The main movie is the foundation for all the content in the document, including all other movie clips. We sometimes refer to the main movie as the main timeline, the main movie timeline, the main Stage, or simply the root.

    Note that while each .swf file contains only one main movie, more than one .swf file can reside in the Flash Player at once—we can load multiple .swf documents (and therefore multiple main movies) onto a stack of levels via the loadMovie() and
    unloadMovie() functions, which we’ll study later.

    Main movies can be manipulated in much the same way as regular movie clips, with the following exceptions:

    • A main movie cannot be removed from a .swf file (although a .swf file, itself, can be removed from the Flash Player).
    • The following movie clip methods do not work when invoked on a main movie: duplicateMovieClip(), removeMovieClip(), and swapDepths()
    • The following properties are not supported by main movies:enabled,
      focusEnabled,hitArea,_name,_parent,tabChildren,
      tabEnabled,tabIndex,trackAsMenu, anduseHandCursor.
    • In Flash 5, event handlers cannot be attached to the main movie. As of Flash Player 6, the following event handler properties can be assigned to
      the main movie: onData(), onEnterFrame(), onKeyDown(), onKeyUp(),
      onMouseDown( ), onMouseMove( ), and onMouseUp( ).
    • Main movies cannot receive keyboard input focus.
    • Main movies can be referenced through the built-in global_rootand_leveln  properties.

    Regular Movie Clips

    Regular movie clips are the most common and fundamental content containers; they hold visual elements and sounds, and they can even react to user input and movie playback through event handlers. For JavaScript programmers who are used to working with DHTML, it may be helpful to think of the main movie as analogous to an HTML document object and regular movie clips as analogous to that document’s layer objects.

    Components

    An improvement over Flash 5 Smart Clips, a Flash MX component is a movie clip that includes a graphical user interface used to customize the clip’s properties in the authoring tool. Components typically are developed by advanced programmers to distribute as self-contained program modules, such as a pull-down menu or slider bar. Components also provide an easy way for less-experienced Flash authors to customize a movie clip’s behavior without knowing how the code of the clip works. We’ll cover components in detail in Chapter 14 and Chapter 16. Flash MX comes with a collection of ready-made interface components known as the Flash UI Components. To access the Flash UI Components, choose Window -> Components.

    Process Clips

    A process clip is a movie clip used not for content but simply to execute a block of code repeatedly. Process clips can be built with an onEnterFrame() event handler or with a timeline loop, as we saw in Chapter8 under “Timeline and Clip Event Loops .”

    As of Flash MX, the functionality of process clips can be partially replaced by the setInterval() function, which executes a function or method periodically. Timed code should be implemented with setInterval(), whereas code synched specifically with the frame rate should be implemented with a process clip. See the Language Reference for a discussion of setInterval( ).

    Script Clips

    Like a process clip, a script clip is an empty movie clip used not for content but for tracking some variable, defining some class, or simply executing some arbitrary script. For example, in Flash 5, we can use a script clip to hold event handlers that detect keypresses or mouse events. In Flash MX, we can use a script clip to create a so-called “code only” component.

    Linked Clips

    A linked clip is a movie clip that either exports from or imports into the Library of a movie. Export and import settings are available through every movie clip’s Linkage option, found in the Library. We most often use linked clips when dynamically generating an instance of a clip directly from a Library symbol using the attachMovie() method, as we’ll see later.

    Seed Clips

    Before the attachMovie() method was introduced in Flash 5, we used the duplicateMovieClip() function to create new movie clips based on some existing clip, called a seed clip. A seed clip is a movie clip that resides on stage solely for the purpose of being copied via duplicateMovieClip(). With the introduction of attachMovie(), which instantiates clips from the Library, the need for on-stage seed clips has diminished. However, we still use seed clips and duplicateMovieClip() when we wish to retain a clip’s transformations and onClipEvent( ) handlers in the process of copying it.

    In a movie that makes heavy use of duplicateMovieClip( ) to dynamically generate content, it’s common to see a row of seed clips on the outskirts of the movie canvas. The seed clips are used only to derive duplicate clips and are, therefore, kept off stage.

    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 1 hosted by Hostway
    Stay green...Green IT