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

50 Chapter 3: Creating Advanced Components in Flash MX 2004
Accessing application scope
Every class that extends the UIObject class has an
application property that stores a reference to
the Application object. You can use this property to access data or methods at the application
level. Because the event handlers and the bindings of a component execute in the context of that
component, using the Application object gives you access to the application scope.
To access the Application object, you must import the Application package in your class file, as
the following example shows:
import mx.core.Application;
Some nonvisual components, such as Validator, do not inherit from the UIObject class. As a
result, some components do not have an
application property. For these components, you can
access the application by using the static property
Application.application.
In the following example, the component calls the
getName() method on the Application object.
Assume that the method is written in the MXML file or some dependent class that uses your
component.
var name:String = application.getName();
Identifying the class, symbol, and owner names
To help Flash find the proper ActionScript classes and packages, and to preserve the component’s
naming, you must set the
symbolName, symbolOwner, and className variables in your
component’s ActionScript class file.
The following table describes these variables:
Property Type Description
symbolName
String Symbol name for the object (name of the ActionScript class). The symbol
name must be the fully qualified class name (for example,
myPackage.MyComponent).
This name must match the Linkage Identifier and ActionScript 2.0 Class
fields in the Create New Symbol dialog box described in “Adding new
symbols” on page 12.
You must declare this variable as static.
symbolOwner
Object Class used in the internal call to the createClassObject() method.
The symbol owner must be the fully qualified class name (for example,
myPackage.MyComponent).
Do not use quotation marks around the
symbolOwner value, since it is of type
Object.
This name must match the Linkage Identifier and ActionScript 2.0 Class
fields in the Create New Symbol dialog box described in “Adding new
symbols” on page 12.
You must declare this variable as static.
className
String Name of the component class. This does not include the package name
and has no corresponding setting in the Flash development environment.
You can use the value of this variable when setting style properties.