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

38 Chapter 2: Creating Basic Components in Flash MX 2004
}
function init() {
setStyle("fontSize", 24);
super.init();
invalidate();
}
function measure() {
_measuredPreferredWidth=500;
_measuredPreferredHeight=200;
}
}
The following MXML file instantiates the BlueButton control. All instances of this BlueButton
control have a default size of 500 by 200 pixels, with a label
fontSize of 24.
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns=”*” >
<BlueButton label="My Big Button" />
</mx:Application>
You can override custom style settings in the MXML file, as the following example shows:
<BlueButton label="My Big Button" fontSize="12" />
Styling custom components
Style properties define the look of a component, from the size of the fonts used to the color of the
background. To change style properties in custom components, use the
setStyle() method in
the component’s
init() function. This applies the same style to all instances of the component,
but Flex application authors can override the settings of the
setStyle() method in their MXML
tags. Any style properties that are not explicitly set in the component’s class file are inherited from
the component’s superclass.
This section includes a class file that extends an existing control. For more information on setting
up the Flash environment and exporting this custom component as a SWC file, see “Creating the
Blue Button” on page 27.
The following ActionScript class file sets the
color and themeColor styles of the BlueButton
control:
class BlueButton extends mx.controls.Button {
static var symbolName:String="BlueButton";
static var symbolOwner:Object = BlueButton;
var className:String = "BlueButton";
function BlueButton() {
}
function init() {
// Set the label text to blue.