User Guide
Table Of Contents
- Contents
- Working with Flash MX 2004
- Creating Basic Components in Flash MX 2004
- Creating Advanced Components in Flash MX 2004
- Contents
- About Creating components
- Writing the component’s ActionScript code
- Simple example of a class file
- General process for writing a class file
- Selecting a parent class
- Identifying the class, symbol, and owner names
- About the component instantiation life cycle
- Writing the constructor
- Specifying clip parameters
- Implementing the constructObject2() method
- Implementing the init() method
- Implementing the createChildren() method
- Implementing the commitProperties() method
- Implementing the measure() method
- Implementing the layoutChildren() method
- Implementing the draw() method
- Defining getters and setters
- Component metadata
- Defining component parameters
- Handling events
- Using the Event metadata
- About invalidation
- Skinning custom controls
- Adding styles
- Making components accessible
- Improving component usability
- Best practices when designing a component
- Using the ModalText example
- Troubleshooting
- Index

Adding events to custom components 33
If your custom SWC file has properties typed Array, do not use data binding to supply initial
values for array properties. For example, if your custom SWC file has a
labels property that is
typed Array, do not use data binding in the MXML as the following example shows:
<yourSWC labels={myArray}/>
<mx:Script>
<![CDATA[
var myArray=["cat", "dog", "bird"];
]]>
</mx:Script>
The problem is that Flex instantiates the SWC file before data binding occurs. Instead, you define
the array using the
<mx:Array> tag, as the following example shows:
<yourSWC>
<labels>
<mx:Array>
<mx:String>cat</mx:String>
<mx:String>dog</mx:String>
<mx:String>bird</mx:String>
</mx:Array>
</labels>
</yourSWC>
Adding events to custom components
All visual controls inherit a large set of events from the base classes, UIObject and UIComponent.
From the UIComponent class, components inherit events such as
focusIn, focusOut, keyDown,
and
keyUp. From the UIObject class, components inherit events such as mouseDown, mouseUp,
mouseOver, and mouseOut. For a complete list of UIObject and UIComponent events, see
Developing Flex Applications.
Components can emit and consume events. In most cases, you want your component to emit an
event and the MXML application to consume and handle it.
Custom components that extend existing Flex classes inherit those events. For example, if you
extend the mx.controls.Button class, you have the set of click-related events at your disposal, in
addition to the events that all controls inherit, such as
mouseOver and mouseDown.
This section describes how to add event handling and emitting functionality to your custom
components.
Handling the initialize event
When Flex finishes creating a component, it emits the component’s
initialize event. This
event is used by MXML developers to populate data, debug, or perform some other function
before the user starts interacting with the application.