Class org.as2lib.env.event.TypeSafeEventListenerSource

Implemented Interfaces

EventListenerSource

Description

TypeSafeEventListenerSource manages listeners in a type-safe manner.

Method Index

new TypeSafeEventListenerSource()
addAllListeners(), addListener(), getAllListeners(), getListenerType(), hasListener(), isListenerTypeChecked(), removeAllListeners(), removeListener()

Inherited from BasicClass

Constructor Detail

TypeSafeEventListenerSource

public function TypeSafeEventListenerSource(listenerType:Function, checkListenerType:Boolean)

Constructs a new TypeSafeEventListenerSource instance.

checkListenerType is by default set to true.

Parameters

listenerTypethe expected type of listeners
checkListenerTypedetermines whether to check that passed-in listeners are of the expected type

Throws

IllegalArgumentExceptionif the passed-in listenerType is null or undefined

Method Detail

getListenerType

public function getListenerType(Void):Function

Returns the expected listener type.

Return

the expected listener type

isListenerTypeChecked

public function isListenerTypeChecked(Void):Boolean

Returns whether a listener's type is checked up on the expected listener type.

Return

true a listener's type is checked else false

addListener

public function addListener(listener):Void

Adds the passed-in listener.

The listener will only be added if it is neither null nor undefined and if it is of the expected listener type specified on construction and if it has not already been added to this listener source.

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

Parameters

listenerthe listener to add

Throws

IllegalArgumentExceptionif the passed-in listener is not of the expected type specified on construction

Specified By

addListener() in org.as2lib.env.event.EventListenerSource

addAllListeners

public 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

listenersthe listeners to add

Throws

IllegalArgumentExceptionif at least one listener in the passed-in listeners array is not of the expected type specified on construction

Specified By

addAllListeners() in org.as2lib.env.event.EventListenerSource

See Also

removeListener

public function removeListener(listener):Void

Removes the passed-in listener.

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

Parameters

listenerthe listener to remove

Specified By

removeListener() in org.as2lib.env.event.EventListenerSource

removeAllListeners

public function removeAllListeners(Void):Void

Removes all added listeners.

Specified By

removeAllListeners() in org.as2lib.env.event.EventListenerSource

getAllListeners

public function getAllListeners(Void):Array

Returns all added listeners that are of the type specified on construction.

Return

all added listeners

Specified By

getAllListeners() in org.as2lib.env.event.EventListenerSource

hasListener

public function hasListener(listener):Boolean

Returns true if passed-in listener has been added.

Parameters

listenerthe listener to check whether it has been added

Return

true if the listener has been added

Specified By

hasListener() in org.as2lib.env.event.EventListenerSource