Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 39

Creating and extending flex 2 components
Hide thumbs Also See for FLEX 2 - CREATING AND EXTENDING COMPONENTS:
Table of Contents

Advertisement

Suppose that you want to pass information about the state of your component to the event
listener as part of the event object. To do so, you create a subclass of the Event class to create
an event, EnableChangeEvent, as the following example shows:
package myEvents
{
//events/myEvents/EnableChangeEvent.as
import flash.events.Event;
public class EnableChangeEvent extends Event
{
// Public constructor.
public function EnableChangeEvent(type:String,
isEnabled:Boolean=false) {
// Call the constructor of the superclass.
super(type);
// Set the new property.
this.isEnabled = isEnabled;
}
// Define static constant.
public static const ENABLE_CHANGED:String = "enableChanged";
// Define a public variable to hold the state of the enable property.
public var isEnabled:Boolean;
// Override the inherited clone() method.
override public function clone():Event {
return new EnableChangeEvent(type, isEnabled);
}
}
}
In this example, your custom class defines a public constructor that takes two arguments:
A String value that contains the value of the
An optional Boolean value that contains the state of the component's
property. By convention, all constructor arguments for class properties are optional, other
than the
argument.
type
From within the body of your constructor, you call the
class properties.
property of the Event object.
type
method to initialize the base
super()
Dispatching custom events
isEnabled
39

Advertisement

Table of Contents
loading

Table of Contents