TypeSafeEventListenerSource

Inherits from:BasicClass
Implements:
  • Author: Simon Wacker
  • Classpath: org.as2lib.env.event.TypeSafeEventListenerSource
  • File last modified: Tuesday, 19 April 2005, 18:20:34
TypeSafeEventListenerSource manages listeners in a type-safe manner.

Constructor

TypeSafeEventListenerSource

function TypeSafeEventListenerSource (
listenerType:Function, checkListenerType:Boolean)
Constructs a new TypeSafeEventListenerSource instance.

checkListenerType is by default set to true.

Parameters:
listenerType :
the expected type of listeners
checkListenerType:
determines whether to check that passed-in listeners are of the expected type
Throws:
IllegalArgumentException if the passed-in listenerType is null or undefined

Instance methods

addAllListeners

function addAllListeners (
listeners:Array) : Void
Adds all listeners contained in the passed-in listeners array.

If the passed-in listeners array is null or undefined it will be ignored.

The individual listeners must be instances of the type specified on construction. If an individual listener is null or undefined it will be ignored.

All listeners that are of the correct type will be added.

Note that the listener type will not be checked if it was turned of on construction.

Note also that the order of the listeners contained in the passed-in listeners array is preserved.

Parameters:
listeners:
the listeners to add
Throws:
IllegalArgumentException if at least one listener in the passed-in listeners array is not of the expected type specified on construction
See also:

addListener

function addListener (
listener) : Void
Adds the passed-in listener.

The listener will only be added if it is not null nor undefined and if it is of the expected listener type specified on construction.

Note that if the passed-in listener has already been added the previously added one will be removed.

Note also that the listener type will not be checked if it was turned of on construction.

Parameters:
listener:
the listener to add
Throws:
IllegalArgumentException if the passed-in listener is not of the expected type specified on construction

getAllListeners

function getAllListeners (
Void) : Array
Returns all added listeners that are of the type specified on construction.
Returns:
all added listeners

getListenerType

function getListenerType (
Void) : Function
Returns the expected listener type.
Returns:
the expected listener type

isListenerTypeChecked

function isListenerTypeChecked (
Void) : Boolean
Returns whether a listener's type is checked up on the expected listener type.
Returns:
true a listener's type is checked else false

removeAllListeners

function removeAllListeners (
Void) : Void
Removes all added listeners.

removeListener

function removeListener (
listener) : Void
Removes the passed-in listener.

The removal will be ignored if the passed-in listener is null or undefined.

Parameters:
listener:
the listener to remove