User Guide

18 Creating Flex Components
Some basic guidelines include the following:
MXML components and ActionScript components both define new ActionScript classes.
Almost anything that you can do in a custom ActionScript custom component, you can
also do in a custom MXML component. However, for simple components, such as
components that modify the behavior of an existing component or add a basic feature to
an existing component, it is simpler and faster to create them in MXML.
When your new component is a composite component that contains other components,
and you can express the positions and sizes of those other components using one of the
Flex layout containers, you should use MXML to define your component.
To modify the behavior of the component, such as the way a container lays out its
children, use ActionScript.
To create a visual component by creating a subclass from UIComponent, use
ActionScript.
To create a nonvisual component, such as a formatter, validator, or effect, use
ActionScript.
To add logging support to your control, use ActionScript. For more information, see
Chapter 11, “Logging,” in Building and Deploying Flex 2 Applications.
For more information on custom MXML components, see Chapter 7, “Creating Simple
MXML Components,” on page 77. For more information on ActionScript components, see
Chapter 9, “Creating Simple Visual Components in ActionScript,” on page 121.
Creating new components
Your application might require you to create components, rather than modifying existing
ones. To create components, you typically create them in ActionScript by creating a subclass
from the UIComponent class. This class contains the generic functionality of all Flex
components. You then add the required functionality to your new component to meet your
application requirements.
For more information, see Chapter 10, “Creating Advanced Visual Components in
ActionScript,” on page 147.
NOTE
The Flash Professional 8 authoring environment does not support ActionScript 3.0.
Therefore, you should not use it to create ActionScript components for Flex 2. Instead,
you should use the Flex Builder IDE.