Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 42

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

Advertisement

eventObj.isEnabled=true;
dispatchEvent(eventObj);
For complete examples that create and dispatch custom events, see
Chapter 8, "Creating
Advanced MXML Components," on page 91
and
Chapter 9, "Creating Simple Visual
Components in ActionScript," on page
121.
Creating static constants for the Event.type property
The constructor of an event class typically takes a single required argument that specifies the
value of the event object's
property. In the previous section, you passed the string
type
to the constructor, as the following example shows:
enableChange
// Define event object, initialize it, then dispatch it.
var eventObj:EnableChangeEvent = new EnableChangeEvent("enableChange");
dispatchEvent(eventObj);
The Flex compiler does not examine the string passed to the constructor to determine if it is
valid. Therefore, the following code compiles, even though
might not
enableChangeAgain
be a valid value for the
property:
type
var eventObj:EnableChangeEvent =
new EnableChangeEvent("enableChangeAgain");
Because the compiler does not check the value of the
property, the only time that your
type
application can determine if
is valid is at run time.
enableChangeAgain
However, to ensure that the value of the
property is valid at compile time, Flex event
type
classes define static constants for the possible values for the
property. For example, the
type
Flex
EffectEvent
class defines the following static constant:
// Define static constant for event type.
public static const EFFECT_END:String = "effectEnd";
To create an instance of an EffectEvent class, you use the following constructor:
var eventObj:EffectEvent = new EffectEvent(EffectEvent.EFFECT_END);
If you incorrectly reference the constant in the constructor, the compiler generates a syntax
error because it cannot locate the associated constant. For example, the following constructor
generates a syntax error at compile time because
is not a predefined constant
MY_EFFECT_END
of the EffectEvent class:
var eventObj:EffectEvent = new EffectEvent(EffectEvent.MY_EFFECT_END);
42
Creating Custom Events

Advertisement

Table of Contents
loading

Table of Contents