12.12. Creating a Component That Subclasses MovieClip


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


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.


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 ...

Get Actionscript Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.