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 simple components 25
super.init();
invalidate(); // Required call so that Flex draws the component.
}
}
8.
Return to the Flash environment. Right-click the square and select Convert to Symbol.
The Convert To Symbol dialog box appears.
9.
In the Convert to Symbol dialog box, set the Name, Identifier, and AS 2.0 Class fields to
greensquare. To access the Identifier and AS 2.0 Class fields, you must select the Export for
ActionScript check box.
10.
Click OK.
Flash adds the greensquare symbol to the Library as a Movie Clip.
11.
Convert the symbol to a component by right-clicking the symbol in the Flash Library and
selecting Component Definition.
12.
In the Component Definition dialog box, set the AS 2.0 Class field to greensquare.
13.
Right-click the symbol in the Flash Library and select Export SWC File.
The Export File dialog box appears.
14.
Save the new SWC file as greensquare.swc.
15.
In a text editor, create a new MXML file that contains the following code:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*">
<greensquare/>
</mx:Application>
16.
Save the MXML file as greentest.mxml. You cannot name the file greensquare.mxml. You must
give it a name that is different from the component’s name, such as greentest.mxml.
17.
Copy the SWC component you created (greensquare.swc) to the same directory as the MXML
file. This should not be the same directory into which you saved the ActionScript and FLA files.
This directory must be in the web application’s directory structure so that Flex can compile a
SWF from the MXML file.
18.
Request the MXML file in your browser or a stand-alone Flash Player. A green square should
appear.
Creating the Orange Circle
This section describes how to create the Orange Circle component. This component is different
from the Green Square because its ActionScript class file exists in a package. As a result, there are
additional steps that you must take to build it in Flash, and then refer to it in your MXML file.
The Orange Circle component prints a shape on the screen. The shape is orange and circular.