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

62 Chapter 3: Creating Advanced Components in Flash MX 2004
The Bindable keyword is required when you use the ChangeEvent metadata keyword. For more
information, see “Bindable” on page 60.
In the following example, the component generates the
change event when the value of the
flavorStr property changes:
[ChangeEvent("change")]
public var flavorStr:String;
When the event specified in the metadata occurs, Flash informs whatever is bound to the
property that the property has changed.
You can also instruct your component to generate an event when a getter or setter function is
called, as the following example shows:
[ChangeEvent("change")]
function get selectedDate():Date
In most cases, you set the change event on the getter function, and dispatch the event on the
setter function.
You can register multiple
change events in the metadata so that more than one event is generated
when the property changes, as the following example shows:
[ChangeEvent("change1")]
[ChangeEvent("change2")]
[ChangeEvent("change3")]
Any one of those events indicates a change to the variable. They do not all have to occur to
indicate a change.
Effect
The Effect metadata keyword defines the name of the property that you can assign to an effect
for the MXML tag.
The
Effect metadata keyword has the following syntax:
[Effect("effect_name")]
The effect_name generally matches the event_name listed in the Effect metadata plus the word
Effect. The following example means that a tag may have a
resizeEffect property assigned to
the effect to play when the resize event triggers:
[Effect("resizeEffect")]
Event
Use the Event metadata keyword to define events dispatched by this component. Add the Event
statements outside the class definition in the ActionScript file so that they are bound to the class
and not a particular member of the class.
The
Event metadata keyword has the following syntax:
[Event("event_name")]