Flex - Event Dispatcher Class


Advertisements


Introduction

  • The EventDispatcher class is the base class for all classes that dispatch events.

  • The EventDispatcher class implements the IEventDispatcher interface.

  • The EventDispatcher class allows any object on the display list to be an event target and as such, to use the methods of the IEventDispatcher interface.

In order to understand EventDispatcher, let us first look what are event and event targets.

What is an Event?

Event is a notification when a particular action is performed.For example, when a button is clicked then Click Event occurs.

What is an Event Target

The Event target serves as the focal point for how events flow through the display list hierarchy.

When an event occurs, Flash Player dispatches an event object into the event flow from the root of the display list. The event object then makes its way through the display list until it reaches the event target, at which point it begins its return trip through the display list.

This round-trip journey to the event target is divided into three phases:

S.N.Phase & Description
1

capture

This phase comprises the journey from the root to the last node before the event target's node

2

target

This phase comprises only the event target node.

3

bubbling

This phase comprises any subsequent nodes encountered on the return trip to the root of the display list.

In general, any class which extends EventDispatcher gets the event dispatching capability.

Class declaration

Following is the declaration for flash.events.EventDispatcher class:

public class EventDispatcher
   extends java.lang.Object
      implements IEventDispatcher 

Public methods

S.N.Method & Description
1

EventDispatcher(target:IEventDispatcher = null)


Aggregates an instance of the EventDispatcher class.
2

addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void

Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.

3

dispatchEvent(event:Event):Boolean

Dispatches an event into the event flow.

4

hasEventListener(type:String):Boolean

Checks whether the EventDispatcher object has any listeners registered for a specific type of event.

5

removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void

Removes a listener from the EventDispatcher object.

6

willTrigger(type:String):Boolean

Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.

Events

Following are the events for flash.events.EventDispatcher class:

S.N.Event & Description
1

activate

Dispatched when the Flash Player gains operating system focus and becomes active.

2

detivate

Dispatched when the Flash Player loses operating system focus and becomes inactive.

Methods inherited

This class inherits methods from the following class:

  • Object


flex_basic_controls.htm

Advertisements