Handling Events - MACROMEDIA FLEX-CREATING ADVANCED COMPONENTS Manual

Creating advanced components
Table of Contents

Advertisement

You add these keywords anywhere inside the class definition. For more information on
embedding assets, see Developing Flex Applications.
To create a SWF file from which you embed assets, create a new FLA file and insert new symbols.
For each symbol, select Export for ActionScript or place the symbols on the stage before saving
the file as a SWF file.

Handling events

The event model is a dispatcher-listener model based on the DOM Level 3 proposal for event
architectures. Every component in the architecture emits events in a standard format, as defined
by the convention. Those events vary across components, depending on the functionality that the
component provides.
Components generate and dispatch events and consume (listen to) other events. An object that
wants to know about another object's events registers with that object. When an event occurs, the
object dispatches the event to all registered listeners by calling a method requested during
registration. To receive multiple events from the same object, you must register for each event.
Although every component can define unique events, events are inherited from the core classes of
the architecture, mx.core.UIObject and mx.core.UIComponent. These classes define low-level
component events, such as
components. Subclasses of these classes inherit and broadcast these events.
Dispatching events
In the body of your component's ActionScript class file, you broadcast events using the
dispatchEvent()
dispatchEvent(
The
argument is the event object that describes the event. You can explicitly build an
eventObj
event object before dispatching the event, as the following example shows:
var eventObj = new Object();
eventObj.type = "myEvent";
dispatchEvent(eventObj);
You can also use the following shortcut syntax that sets the value of the
event object and dispatches the event in a single line:
dispatchEvent({type:"myEvent"});
The event object has an implicit property,
the event.
For each event that your custom component dispatches, you add an
defining that event; for example:
[Event("myEvent")]
You add these keywords immediately before the class definition. If you do not identify an event in
the class file with the
compilation, and Flex ignores this event triggered by the component during runtime.
,
,
draw
resize
method. The
dispatchEvent()
)
metadata keyword, the compiler ignores the event during
Event
,
, and others that are fundamental to all
move
load
method has the following signature:
, that is a reference to the object that triggered
target
Writing the component's ActionScript code
property for the
type
metadata keyword
Event
15

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX-CREATING ADVANCED COMPONENTS and is the answer not in the manual?

This manual is also suitable for:

Flex

Table of Contents