Accessibility
 
Home / Developer Center / Macromedia Flash Developer Center /

Macromedia Flash Article

Icon or Spacer Icon or Spacer Icon or Spacer
Brian Lesser
Brian Lesser

Ryerson University
 
Title: Creating movie clip subclasses


Building movie clips with predefined behaviors is easier in Macromedia Flash MX than it was in Flash 5. For example, you don't need to use a child movie clip to provide a predefined event handler for every instance of a parent movie clip. You also don't need to write functions that are called by event handlers just to centralize your code.


In Macromedia Flash MX, you can use the object-oriented features of ActionScript to create object types (generally called classes) that include event-handling methods. This ability allows you to "prepackage" movie clips with event handlers. Here's the basic process for this time-saving technique: You first create a particular class in ActionScript. You then define how movie clips associated with that class will behave by adding event handlers to the class definition. Finally, you connect your class with a particular movie clip by "registering" the class with the movie clip's linked indentifier in the Library.

Once this process is complete, Macromedia Flash MX automatically associates your class and its event handlers with every instance of the movie clip. Moreover, Macromedia Flash MX provides ways to set up each new instance of the movie clip with its own unique property values before it appears in the movie. This tutorial provides a simple example of how to do this, followed by a more extended puzzle game example.


Sample files
Download the FLA files for both tutorials:

Windows   Macintosh
Download the sample file mc_subclasses.zip (12K)   Download the sample file mc_subclasses.sit (12K)

 

Table of contents

·

Tutorial 1: Using a movie clip subclass to make a bouncing ball animation

·

Tutorial 2: Creating a more extensive, grab-and-match puzzle

   
  Next

About the author
Brian Lesser works in Ryerson University's Computing and Communications Services, where he has the ungainly title of Assistant Director, Teaching and Technology Support. Brian also teaches in Ryerson's School of Image Arts and is a contributor to the forthcoming Macromedia Flash MX ActionScript Bible (Hungry Minds, Inc., June 2002).