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

76 Chapter 3: Creating Advanced Components in Flash MX 2004
bTextChanged = true;
invalidate();
}
function get text():String
{
if (bTextChanged)
return __text;
return text_mc.text;
}
// Handle events that are dispatched by the children.
function handleEvent(evt:Object):Void
{
if (evt.type == "change")
{
dispatchEvent({ type: "change" });
}
else if (evt.type == "focusOut")
{
text_mc.editable = false;
}
else if (evt.type = "click")
{
text_mc.editable = !text_mc.editable;
}
}
}
The following is an example MXML file that instantiates the ModalText control and sets the
labelPlacement property to "left":
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns=”*”
width="800" height="400">
<ModalText labelPlacement="left"/>
</mx:Application>
Troubleshooting
This section describes some common problems and their solutions when creating components for
Flex in Flash.
I get an error "don't know how to parse ..." when I try to use the component from MXML.
This means that the compiler could not find the SWC file, or the contents of the SWC file did
not list the component. The MXML tag must match the
symbolName for the component. Also,
ensure that the SWC file is in a directory that Flex searches, and ensure that your
xmlns property
is pointing to the right place. Try moving the SWC file to the same directory as the MXML file
and setting the namespace to "*" as the following example shows:
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*">
For more information, see “Using SWC files” on page 18.