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

45
CHAPTER 3
Creating Advanced Components in
Flash MX 2004
This chapter describes the details of creating visual, interactive components in the Macromedia
Flash MX 2004 workspace for use in Macromedia Flex applications. The majority of the work is
in writing the ActionScript class file, which derives from Flex existing classes, and adding your
own custom functionality.
For a set of simple examples that show the basics of component development, see Chapter 2,
“Creating Basic Components in Flash MX 2004,” on page 23. If you are unfamiliar with working
in the Flash environment, see Chapter 1, “Working with Flash MX 2004,” on page 5.
Contents
About Creating components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Writing the component’s ActionScript code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Skinning custom controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Adding styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Making components accessible. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Improving component usability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Best practices when designing a component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Using the ModalText example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Troubleshooting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
About Creating components
This section describes the general process for creating a component that extends an existing Flash
MX 2004 class. If you want to create a component that is based on the Button control, for
example, you can subclass the mx.controls.Button class. However, if you want to invent your own
component, you will likely extend either the mx.core.UIComponent or mx.core.UIObject class.
Choosing one of these base classes is discussed later, but Macromedia recommends that most
custom components extend the UIComponent class rather than the UIObject class.