Broadcaster

Kind of class:public interface
Package:com.bourre.events
Inherits from:none
Implemented by:
Version:1.0
Author:Francis Bourre
Classpath:com.bourre.events.Broadcaster
File last modified:Monday, 24 November 2008, 11:36:53

Summary


Instance methods
  • addListener (listener:Object) : Boolean
    • Adds the passed-in listener as listener for all events dispatched
  • removeListener (listener:Object) : Boolean
    • Removes the passed-in listener object from this event
  • addEventListener (type:String, listener:Object, rest) : Boolean
    • Adds an event listener for the specified event type.
  • removeEventListener (type:String, listener:Object) : Boolean
    • Removes the passed-in listener for listening the specified event.
  • broadcastEvent (e:Event) : void
    • Broadcast the passed-in event object to listeners
  • removeAllListeners : void
    • Removes all listeners registered in this event broadcaster.
  • hasListenerCollection (type:String) : Boolean
    • Returns true if this event broadcaster has
  • isRegistered (listener:Object, type:String = null) : Boolean
    • Returns true if the passed-in listener object is registered

Instance methods

addEventListener

public function addEventListener (
type:String, listener:Object, rest) : Boolean

Adds an event listener for the specified event type.
There is two behaviors for the addEventListenerfunction :
  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 :
name of the event for which register the listener
listener:
object or function which will receive this event
rest :
additional arguments for the function listener
Returns:
  • true if the function have been succesfully added as
    listener fot the passed-in event
Throws:
  • {VISDOC_LINK_0}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

public function addListener (
listener:Object) : Boolean

Adds the passed-in listener as listener for all events dispatched
by this event broadcaster. The function returns trueif 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:
the listener object to add as global listener
Returns:
  • true if the listener have been added during this call
Throws:
  • {VISDOC_LINK_0}IllegalArgumentException — If the passed-in listener
    listener doesn't match the listener type supported by this event
    broadcaster
  • {VISDOC_LINK_1}IllegalArgumentException — If the passed-in listener
    is a function

broadcastEvent

public function broadcastEvent (
e:Event) : void

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 object to broadcast
Throws:
  • {VISDOC_LINK_0}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

hasListenerCollection

public function hasListenerCollection (
type:String) : Boolean

Returns true if this event broadcaster has
listeners for the passed-in event type.
Parameters:
type:
name of the event for which look for listener
Returns:
  • true if this event broadcaster has
    listeners for the passed-in event type

isRegistered

public function 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. 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 to look for registration
type :
event type to look at
Returns:
  • true if the passed-in listener should receive notification
    of the passed-in event type

removeAllListeners

public function removeAllListeners (
) : void

Removes all listeners registered in this event broadcaster.

removeEventListener

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

Removes the passed-in listener for listening the specified event. The
listener could be either an object or a function.
Parameters:
type :
name of the event for which unregister the listener
listener:
object or function to be unregistered
Returns:
  • true if the listener have been successfully removed
    as listener for the passed-in event

removeListener

public function removeListener (
listener:Object) : Boolean

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:
the listener object to remove from
this event broadcaster object
Returns:
  • true if the object have been successfully
    removed from this event broadcaster
Throws:
  • {VISDOC_LINK_0}IllegalArgumentException — If the passed-in listener
    is a function