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.