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

23
CHAPTER 2
Creating Basic Components in Flash MX 2004
This chapter includes a set of simple examples that illustrate the basics of component
development. The first part of the chapter introduces the Green Square, Orange Circle, and Blue
Button components, which illustrate simple component construction and usage. The latter part
of the chapter expands on the simple components and describes how to use event handling,
styling, skinning, and other techniques when creating your components.
If you are unfamiliar with working in the Macromedia Flash environment, see Chapter 1,
“Working with Flash MX 2004,” on page 5. For more advanced information on creating
components, see Chapter 3, “Creating Advanced Components in Flash MX 2004,” on page 45.
Contents
Creating simple components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Working with component properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Binding properties to a custom component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Adding events to custom components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Setting default sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Styling custom components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Skinning custom components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Creating compound components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Creating simple components
This section describes how to create simple components in Macromedia Flash for Macromedia
Flex. As with creating any Hello World–style example, these procedures ignore some practices to
help new component developers quickly achieve success and begin creating components.
This section describes how to create the following components:
Green Square Create a component that exists in a flat namespace. This component’s
ActionScript class file is not part of a package.