Methods Frames | No Frames

mx.events
Class EventDispatcher


Direct Known Subclasses
           mx.charts.chartClasses.ChartComponent, mx.events.UIEventDispatcher

class EventDispatcher

The EventDispatcher class is a mixin class that implements event dispatching and listening for events unrelated to the Flash Player. The methods dispatchEvent(), addEventListener(), and removeEventListener() are mixed in to Operation, Repeater, Validator, and several other classes that dispatch such events. Events related to the Flash Player, such as mouse events, are handled by the related mixin class UIEventDispatcher, which extends EventDispatcher.



Methods
       addEventListener( eventType: String, eventListener) :  Void
Registers the specified object or function as a listener for any events of the specified type that are broadcast from this object.
       dispatchEvent( eventObj: Object) :  Boolean
Broadcasts the specified event object to all of this object's listeners that were registered via addEventListener() to receive this type of event.
staticinitialize( object: Object) :  Void
Adds methods to the specified object to support event dispatching and listening.
       removeEventListener( eventType: String, eventListener) :  Void
Unregisters the specified object or function as a listener for events of the specified type that are broadcast from this object.



Method Detail

addEventListener

addEventListener( eventType: String, eventListener) :  Void

Registers the specified object or function as a listener for any events of the specified type that are broadcast from this object. If the specified listener has already been added, it is first removed and then re-added.

When an object calls dispatchEvent(eventObj), eventObj will be broadcast to all the listeners for the type of event specified by eventObj.type. For example, executing myButton.dispatchEvent({type: "click"}) will cause the object {type: "click", target: myButton} to be broadcast to a listener registered via myButton.addEventListener("click", listener).

When an event is broadcast to a listener which is an object, such as a document object, that object's handleEvent() method, if it exists, is called with this set to the listener object. The event object is passed to handleEvent() as its sole argument. This method can then inspect the type property of its argument to discover what type of event it has received, and the target property to discover which object dispatched the event. The handleEvent() method should not return a value.

When an event is broadcast to a listener which is a function -- either a method of some class or an anonymous function -- that listener function is called with this set to the dispatching object. The event object is passed to the listener function as its sole argument. The listener function should not return a value.

The above rule for the context in which listener functions are executed means that if you write a document method such as myButton_click() and register it as one of myButton's listeners using myButton.addEventListener("click", myButton_click), then when myButton_click() is called, this will be myButton, not the document. This is probably not what you expect, because if you write <mx:Button id="myButton" click="myButton_click()"/>, the MXML compiler ensures that myButton_click() is executed in the context of the document. To change the context in which the listener method is executed from the button to the document, you can use the utility method mx.utils.Delegate.create().

If there are multiple listeners, the order in which the event object is broadcast to each one is unspecified and subject to change.

Parameters
    eventType: String - String specifying the type of the event, such as <code>"click"</code> or <code>"change"</code>.
    eventListener - Object or function to receive that type of event.

See Also
    mx.utils.Delegate


dispatchEvent

dispatchEvent( eventObj: Object) :  Boolean

Broadcasts the specified event object to all of this object's listeners that were registered via addEventListener() to receive this type of event.

To be dispatched as an event object, an object must have at least a type property which specifies the event's type, such as "click". Before the event object is broadcast, a target property is added to it; this property is a reference to the dispatching object.

For example, executing myButton.dispatchEvent({type: "click"}) will cause the object {type: "click", target: myButton} to be broadcast to a listener registered via myButton.addEventListener("click", listener).

See addEventListener() for information about how events are received by listeners.

If eventObj.bubbles is true, the event will be propagated up the parent chain and broadcast from each ancestor.

Events are broadcast immediately; all listeners receive the event before the call to dispatchEvent() returns.

Parameters
    eventObj: Object - An object describing the event; it must have at least a <code>type</code> property.


initialize

static  initialize( object: Object) :  Void

Adds methods to the specified object to support event dispatching and listening.

Parameters
    object: Object - Object to receive the methods.


removeEventListener

removeEventListener( eventType: String, eventListener) :  Void

Unregisters the specified object or function as a listener for events of the specified type that are broadcast from this object. If the specified listener has already been removed, nothing happens.

Parameters
    eventType: String - String specifying the type of the event, such as <code>"click"</code> or <code>"change"</code>.
    eventListener - Object or function to receive that type of event.


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flex/15/asdocs_en/mx/events/EventDispatcher.html