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 27
13.
Right-click the symbol in the Flash Library and select Export SWC File.
14.
Save the new SWC file as orangecircle.swc.
15.
In a text editor, create an MXML file that contains the following code:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
xmlns:myp="myPackage.*" >
<myp:orangecircle />
</mx:Application>
You must add a namespace declaration that includes the package whenever you access a
component that uses ActionScript files in packages.
You cannot name the file orangecircle.mxml. You must give it a name that is different from the
component’s name, such as oc.mxml.
16.
Save the MXML file.
17.
Copy the SWC file that you created (orangecircle.swc) to the same directory as the MXML file.
This should not be the same directory in which you saved the ActionScript and FLA file. 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. An orange circle should
appear.
Creating the Blue Button
This procedure shows you how to extend an existing Flex control. In this example, it is a button.
The button’s border and text are blue. When you insert the Blue Button component into your
Flex application, it inherits all of the events, behaviors, and capabilities of a standard Button
control, but it has a customized style.
To create the Blue Button:
1.
Set up the Flash environment by adding the Flex components and class files. For more
information, see “Adding Flex classes and components to the Flash IDE” on page 8.
2.
In Flash, create a FLA file.
3.
Edit the FLA file’s local classpath settings to include the following two classpath entries:
■ $(LocalData)/Flex Classes
■ . (the dot)
For more information, see “Changing the Flash classpath” on page 10.
4.
Select Insert > New Symbol.
The Create New Symbol dialog box appears.
Rather than convert existing graphical assets to a symbol, you create a symbol and add
dependent components to it as assets.