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

Creating compound components 43
The following ActionScript class file creates a component that instantiates TextArea and
Button controls:
// Import all necessary classes.
import mx.core.UIComponent;
import mx.controls.Button;
import mx.controls.TextArea;
[Event("click")]
class CompoundComponent extends UIComponent {
static var symbolName:String="CompoundComponent";
static var symbolOwner:Object = CompoundComponent;
var className:String = "CompoundComponent";
function CompoundComponent() {
}
function init() {
super.init();
invalidate();
}
// Declare two children member variables.
var text_mc:TextArea;
var mode_mc:Button;
function createChildren():Void {
if (mode_mc == undefined)
createClassObject(Button, "mode_mc", 1, { });
if (text_mc == undefined)
createClassObject(TextArea, "text_mc", 0, { preferredWidth: 150,
editable: false });
mode_mc.addEventListener("click", this);
mode_mc.label = "Click Me";
}
function layoutChildren():Void {
mode_mc.move(text_mc.width/2-5, 50);
}
// Handle events that are dispatched by the children.
function handleEvent(evt:Object):Void {
if (evt.type == "click")
text_mc.text = "the button was clicked";
}
}