O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

12.12. Creating a Component That Subclasses MovieClip

Problem

You want to create a reusable component, such as an interface widget, or even a component without a UI.

Solution

Create a new movie clip symbol. On the first frame of the symbol’s timeline define the component class (which must inherit from MovieClip). Then register the class using Object.registerClass( ). All this code should be encapsulated between #initclip and #endinitclip pragmas.

Discussion

Components are a way of encapsulating movie clips so that the instances can be easily configured by setting parameters through a user interface at authoring time or through a programmatic interface at runtime. For those who prefer to use Flash as a design tool, many ready-made components (such as those included in the Flash UI Component sets) can be dragged into a movie, and parameters can be set via the Property inspector or Parameters panel. These components add functionality to the movie without the designer having to write all the code that is entailed. For our purposes, however, we will use the term “component” more specifically to refer to subclasses of MovieClip. In other words, we will be discussing components that are controlled programmatically instead of those that are controlled via an author-time user interface.

There are five (or six) basic steps to creating a component:

  1. Create a new movie clip symbol and give it a name in the Symbol Property dialog box (accessed under Properties from the Library panel’s pop-up Options ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required