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

Writing the component’s ActionScript code 63
The following example identifies the myClickEvent event as an event that the component
can dispatch:
[Event("myClickEvent")]
If you do not identify an event in the class file with the Event metadata keyword, the compiler
ignores the event during compilation, and Flex ignores this event triggered by the component
during runtime. The metadata for events is inherited from the parent class, however, so you do
not need to tag events that are already tagged with the
Event metadata keyword in the parent
class.
The following example shows the
Event metadata for the UIObject class, which handles the
resize, move, and draw events:
...
[Event("resize")]
[Event("move")]
[Event("draw")]
class mx.core.UIObject extends MovieClip {
...
}
Inspectable
You specify the user-editable (or inspectable) parameters of a component in the class definition for
the component using the
Inspectable metadata keyword. If you tag a property as inspectable, it
appears in the Component inspector of the Flash user interface.
Prior to the availability of this metadata keyword, you had to define the property in the
ActionScript class file and in the Component inspector, which introduced the possibility of errors
because the property was defined in multiple locations. Now, you define the property only once.
The
Inspectable metadata statement must immediately precede the property’s variable
declaration to be bound to that property.
The
Inspectable metadata keyword has the following syntax:
[Inspectable(value_type=value[,option=value,...])]
property_declaration name:type;
The following table describes the options of the Inspectable metadata keyword:
Option Type Description
category
String (Optional) Groups the property into a specific subcategory in the
Property inspector of the Flash user interface.
defaultValue
String or
Number
(Required) Defines the default value for the inspectable property.
This property is required if used in a getter or setter function. The
default value is determined from the property definition.
enumeration
String (Optional) Specifies a comma-delimited list of legal values for the
property. Only these values are allowed; for example,
item1, item2,
item3.