Flash CS3 Documentation |
|||
| Using ActionScript 2.0 Components > Creating Components > Selecting a parent class | |||
The first thing to decide when creating a component is whether to extend one of the version 2 classes. If you choose to extend a version 2 class, you can either extend a component class (for example, Button, CheckBox, ComboBox, List, and so on) or one of the base classes, UIObject or UIComponent. All the component classes, except the Media components, extend the base classes; if you extend a component class, the class automatically inherits from the base classes as well.
The two base classes supply common features for components. By extending these classes, your component begins with a basic set of methods, properties, and events.
You don't have to create a subclass UIObject or UIComponent or any other classes in the version 2 framework. Even if your component classes inherit directly from the MovieClip class, you can use many powerful component features: export to a SWC file or compiled clip, use built-in live preview, view inspectable properties, and so on. However, if you want your components to work with the Adobe version 2 components, and use the manager classes, you need to extend UIObject or UIComponent.
The following table briefly describes the version 2 base classes:
|
Base class |
Extends |
Description |
|---|---|---|
mx.core.UIObject
|
MovieClip |
UIObject is the base class for all graphical objects. It can have shape, draw itself, and be invisible. UIObject provides the following functionality:
|
mx.core.UIComponent
|
UIObject |
UIComponent is the base class for all components. UIComponent provides the following functionality:
|
Components based on version 2 of the Adobe Component Architecture descend from the UIObject class, which is a subclass of the MovieClip class. The MovieClip class is the base class for all classes in Flash that represent visual objects on the screen.
UIObject adds methods that allow you to handle styles and events. It posts events to its listeners just before drawing (the draw event is the equivalent of the MovieClip.onEnterFrame event), when loading and unloading (load and unload), when its layout changes (move, resize), and when it is hidden or revealed (hide and reveal).
UIObject provides alternate read-only variables for determining the position and size of a component (width, height, x, y), and the move() and setSize() methods to alter the position and size of an object.
The UIObject class implements the following:
For more information, see ActionScript 2.0 Components Language Reference.
The UIComponent class is a subclass of UIObject (see UIComponent class in ActionScript 2.0 Components Language Reference). It is the base class of all components that handle user interaction (mouse and keyboard input). The UIComponent class allows components to do the following:
To make component construction easier, you can extend any class; you are not required to extend the UIObject or UIComponent class directly. If you extend any other version 2 component's class (except the Media components), you extend UIObject and UIComponent by default. Any component class listed in the Component dictionary can be extended to create a new component class.
For example, if you want to create a component that behaves almost the same as a Button component does, you can extend the Button class instead of re-creating all the functionality of the Button class from the base classes.
The following figure shows the version 2 component hierarchy:
Version 2 component hierarchy
For a sample of a FlashPaper version of the arch_diagram.swf file, see the Flash Samples page at www.adobe.com/go/learn_fl_samples.
You can choose not to extend a version 2 class and have your component inherit directly from the ActionScript MovieClip class. However, if you want any of the UIObject and UIComponent functionality, you'll have to build it yourself. You can open the UIObject and UIComponent classes (First Run/Classes/mx/core) to examine how they are constructed.
Flash CS3