About The Component Instantiation Life Cycle; Writing The Constructor - MACROMEDIA FLEX-CREATING ADVANCED COMPONENTS Manual

Creating advanced components
Table of Contents

Advertisement

The UIComponent (mx.core.UIComponent) class is a subclass of the UIObject class. It defines
high-level behaviors that are specific to a graphical object. The UIComponent class handles end-
user interactions (such as clicking and focus) and component enabling and disabling. The
UIComponent class inherits all the methods, properties, and events of the UIObject class.
Note: UIComponent also handles dragging, but you should not override the
when defining custom components.
Extending other classes
To make component construction easier, you can extend a subclass for any class in the component
architecture; you do not need to extend the UIObject or UIComponent class directly. 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 recreating all the functionality of the Button class
from the base classes. If you extend any other component's class, you extend these base classes by
default, because all components are subclasses of the UIComponent class, which is a subclass of
the UIObject class.
However, if you only want to modify a Button's behavior, it is simpler to extend the Button class
as a custom MXML component. For more information, see Developing Flex Applications.

About the component instantiation life cycle

When you instantiate a new component, Flex calls a number of methods, and those methods call
other methods that you can override. Instantiating a new component in your application triggers
the following method calls by Flex:
Constructor
1
2
init()
3
createChildren()
4
commitProperties()
5
measure()
6
layoutChildren()
7
draw()
Each of the
commitProperties()
corresponding invalidate method. For more information, see
The remaining sections describe each of these methods. For the purposes of initialization, you do
not need to add any explicit calls to these methods, because Flex initiates each call.

Writing the constructor

Generally, component constructors should be empty so that the object can be customized with its
properties interface. For example, the following code shows a constructor for MyComponent:
function MyComponent() {
}
In this example, when a new component is instantiated, Flex calls the
constructor.
You do not generally set properties in the constructor because the properties can be overridden by
later method calls. For more information, see
8
Creating Advanced Components
,
,
measure()
layoutChildren()
"Implementing the init() method" on page
startDrag()
, and
methods has a
draw()
"About invalidation" on page
MyComponent()
method
17.
9.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents