Packagecom.bourre.events
Classpublic class EventBroadcaster
ImplementsBroadcaster
SubclassesPluginBroadcaster

Player version: Flash Player 9.0
Language version: ActionScript 3.0

The EventBroadcaster class is the cornerstone of the Lowra event system. The main reason which explains the presence of this object whereas the existence of the native EventDispatcher class is the lack of flexibility of that class :

With the EventBroadcaster class it's possible to work with many kinds of listeners, as listed below :

The Lowra's event broadcaster also offer many methods to dispatch event from different type of events object. More formally, it's possible to dispatch an event object, or an anonymous object which will be converted into a DynBasicEvent before the broadcast, all of its properties are then copied into this event object.

Another big difference with the native dispatcher is the fact that listeners are systematically stored using weak references, restricting the usage of anonymous listeners which can't be unregistered due to the lack of reference to it.

Composition is privileged over inheritance by the use of a source object parameter for the broadcaster. That property, if set, result in that all event objects dispatched by the EventBroadcaster which have their target set to null will have that object as source instead of the dispatcher itself.

Optionally the EventBroadcaster can restrict the type of listeners to a specific type, in that case the broadcaster only accept the registration of objects which implements or extends the specified Class.



Protected Properties
 PropertyDefined by
  _cType : Class
EventBroadcaster
  _mAll : Collection
EventBroadcaster
  _mDelegate : HashMap
EventBroadcaster
  _mEventListener : HashMap
EventBroadcaster
  _mType : HashMap
EventBroadcaster
  _oSource : Object
EventBroadcaster
Public Methods
 MethodDefined by
  
EventBroadcaster(source:Object = null, type:Class = null)
Creates an new EventBroadcaster object with the passed-in source object as source for events.
EventBroadcaster
  
addEventListener(type:String, listener:Object, ... rest):Boolean
Adds an event listener for the specified event type.
EventBroadcaster
  
addListener(listener:Object):Boolean
Adds the passed-in listener as listener for all events dispatched by this event broadcaster.
EventBroadcaster
  
broadcastEvent(e:Event):void
Broadcast the passed-in event object to listeners according to the event's type.
EventBroadcaster
  
dispatchEvent(o:Object):void
Broadcast an event using an anonymous object.
EventBroadcaster
  
[static] Returns a static instance of the class.
EventBroadcaster
  
getListenerCollection(type:String = null):Collection
Returns a Collection view of listeners for the passed-in event type.
EventBroadcaster
  
hasListenerCollection(type:String):Boolean
Returns true if this event broadcaster has listeners for the passed-in event type.
EventBroadcaster
  
isEmpty():Boolean
Returns true if this event broadcaster contains no listeners for any event.
EventBroadcaster
  
isRegistered(listener:Object, type:String = null):Boolean
Returns true if the passed-in listener object is registered as listener for the passed-in event type.
EventBroadcaster
  
Removes all listeners registered in this event broadcaster.
EventBroadcaster
  
removeEventListener(type:String, listener:Object):Boolean
Removes the passed-in listener for listening the specified event.
EventBroadcaster
  
removeListener(listener:Object):Boolean
Removes the passed-in listener object from this event broadcaster.
EventBroadcaster
  
removeListenerCollection(type:String):void
Removes the complete collection of listeners for a specified event type.
EventBroadcaster
  
setListenerType(type:Class):void
Defines the type of listeners this event broadcaster support.
EventBroadcaster
  
toString():String
Returns the String representation of this object.
EventBroadcaster
Protected Methods
 MethodDefined by
  
_broadcastEvent(c:Collection, e:Event):void
Broadcast the passed-in event to the listeners contained in the passed-in Collection.
EventBroadcaster
Property detail
_cTypeproperty
protected var _cType:Class

Player version: Flash Player 9.0
Language version: ActionScript 3.0

_mAllproperty 
protected var _mAll:Collection

Player version: Flash Player 9.0
Language version: ActionScript 3.0

_mDelegateproperty 
protected var _mDelegate:HashMap

Player version: Flash Player 9.0
Language version: ActionScript 3.0

_mEventListenerproperty 
protected var _mEventListener:HashMap

Player version: Flash Player 9.0
Language version: ActionScript 3.0

_mTypeproperty 
protected var _mType:HashMap

Player version: Flash Player 9.0
Language version: ActionScript 3.0

_oSourceproperty 
protected var _oSource:Object

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Constructor detail
EventBroadcaster()constructor
public function EventBroadcaster(source:Object = null, type:Class = null)

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Creates an new EventBroadcaster object with the passed-in source object as source for events. If the source parameter is omitted the source of events will be this event broadcaster.

Optionnaly the type of listeners objects can be restricted, in that case you just have to pass the class of listener in the type parameter.

Parameters
source:Object (default = null) — an object used as target instead of this event broadcaster for event object which have a null target
 
type:Class (default = null) — an optional class for listener
Method detail
_broadcastEvent()method
protected function _broadcastEvent(c:Collection, e:Event):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Broadcast the passed-in event to the listeners contained in the passed-in Collection.

Parameters
c:CollectionCollection of listeners to which send the event
 
e:Event — event to broadcast to listeners

Throws
UnsupportedOperationException — If one listener is an object which have neither a function with the same name than the event type nor a function called handleEvent
addEventListener()method 
public function addEventListener(type:String, listener:Object, ... rest):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Adds an event listener for the specified event type. There is two behaviors for the addEventListener function :

  1. The passed-in listener is an object : The object is added as listener only for the specified event, the object must have a function with the same name than type or at least a handleEvent function.
  2. The passed-in listener is a function : A Delegate object is created and then added as listener for the event type. There is no restriction on the name of the function. If the rest is not empty, all elements in it is used as additional arguments into the delegate object.

Parameters
type:String — name of the event for which register the listener
 
listener:Object — object or function which will receive this event
 
... rest — additional arguments for the function listener

Returns
Booleantrue if the function have been succesfully added as listener fot the passed-in event

Throws
UnsupportedOperationException — If the listener is an object which have neither a function with the same name than the event type nor a function called handleEvent
addListener()method 
public function addListener(listener:Object):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Adds the passed-in listener as listener for all events dispatched by this event broadcaster. The function returns true if the listener have been added at the end of the call. If the listener is already registered in this event broadcaster the function returns false.

Note : The addListener function doesn't accept functions as listener, functions could only register for a single event.

Parameters
listener:Object — the listener object to add as global listener

Returns
Booleantrue if the listener have been added during this call

Throws
IllegalArgumentException — If the passed-in listener listener doesn't match the listener type supported by this event broadcaster
 
IllegalArgumentException — If the passed-in listener is a function
broadcastEvent()method 
public function broadcastEvent(e:Event):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Broadcast the passed-in event object to listeners according to the event's type. The event is broadcasted to both listeners registered specifically for this event type and global listeners in the broadcaster.

If the target property of the passed-in event is null, it will be set using the value of the source property of this event broadcaster.

Parameters
e:Event — event object to broadcast

Throws
UnsupportedOperationException — If one listener is an object which have neither a function with the same name than the event type nor a function called handleEvent
dispatchEvent()method 
public function dispatchEvent(o:Object):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Broadcast an event using an anonymous object. The only requirement for objects passed as argument in this function is that they must have a type property. The target property will be set with this event broadcaster's source if there is no source specified.

The concret event object broadcasted to listener is a DynBasicEvent decorated with the property of the passed-in object.

Parameters
o:Object — an anonymous object used to decorate a DynBasicEvent

Throws
UnsupportedOperationException — If one listener is an object which have neither a function with the same name than the event type nor a function called handleEvent
getInstance()method 
public static function getInstance():EventBroadcaster

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns a static instance of the class.

The presence of a getInstance method in the EventBroadcaster class doesn't mean that the class is a singleton, it's simply a convenient way to let application developers broadcasting events that correspond to user gestures and requests over the whole application.

Returns
EventBroadcaster — a static instance of the class
getListenerCollection()method 
public function getListenerCollection(type:String = null):Collection

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns a Collection view of listeners for the passed-in event type. The returned collection is a reference to the internal collection of this event broadcaster, resulting that there's no guarantee that collection cannot be altered by another object. If the type parameter is omitted, the function returns the collection of global listeners objects (all objects that haven't register for a specific event).

Parameters
type:String (default = null) — the event name for which get a collection, if not defined, the collection of global listeners is returned

Returns
CollectionCollection of listeners corresponding to the passed-in event type
hasListenerCollection()method 
public function hasListenerCollection(type:String):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns true if this event broadcaster has listeners for the passed-in event type.

Parameters
type:String — name of the event for which look for listener

Returns
Booleantrue if this event broadcaster has listeners for the passed-in event type
isEmpty()method 
public function isEmpty():Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns true if this event broadcaster contains no listeners for any event.

Returns
Booleantrue if this event broadcaster contains no listeners for any event.
isRegistered()method 
public function isRegistered(listener:Object, type:String = null):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns true if the passed-in listener object is registered as listener for the passed-in event type. If the type parameter is omitted, the function returns true only if the listener is registered as global listener.

Note : the listener could be either an object or a function.

Parameters
listener:Object — object to look for registration
 
type:String (default = null) — event type to look at

Returns
Booleantrue if the passed-in listener should receive notification of the passed-in event type
removeAllListeners()method 
public function removeAllListeners():void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Removes all listeners registered in this event broadcaster.

removeEventListener()method 
public function removeEventListener(type:String, listener:Object):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Removes the passed-in listener for listening the specified event. The listener could be either an object or a function.

Parameters
type:String — name of the event for which unregister the listener
 
listener:Object — object or function to be unregistered

Returns
Booleantrue if the listener have been successfully removed as listener for the passed-in event
removeListener()method 
public function removeListener(listener:Object):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Removes the passed-in listener object from this event broadcaster. The object is removed as listener for all events the broadcaster may dispatch.

Parameters
listener:Object — the listener object to remove from this event broadcaster object

Returns
Booleantrue if the object have been successfully removed from this event broadcaster

Throws
IllegalArgumentException — If the passed-in listener is a function
removeListenerCollection()method 
public function removeListenerCollection(type:String):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Removes the complete collection of listeners for a specified event type.

Parameters
type:String — the event type for which remove all listeners
setListenerType()method 
public function setListenerType(type:Class):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Defines the type of listeners this event broadcaster support. Functions are not concerned by this restriction.

Parameters
type:Class — the type of the listener this event broadcaster support

Throws
IllegalArgumentException — If one of the listener already contained in this event broadcaster doesn't match the passed-ni type
toString()method 
public function toString():String

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns the String representation of this object.

The function return a string like com.bourre.events::EventBroadcaster<ListenerType> for a typed broadcaster. The string between the < and > is the name of the type of the broadcaster's global listeners. If the broadcaster is an untyped broadcaster the function will simply return the result of the PixlibStringifier.stringify call.

Returns
StringString representation of this object.