EventListenerSource
EventSupport
provides simple access to events.
To apply event abilities to your class its only necessary to extend
EventSupport
. It holds in the private instance variable
distributorControl
a reference to
SimpleConsumableCompositeEventDistributionControl.
To allow additional listener types to be checked by addListener,
addAddListener its only necessary to add acceptListenerType(AnyType);
within the constructor of the extended class.
It is necessary for sending a event to recieve the matching distributor with
distributorControl.getDistributor(AnyType)
and execute the event to it.
Example code:
class Controller extends EventSupport {
private var model:Model;
private var distributor:View;
public function Controller(Void) {
distributorControl.acceptListenerType(View);
distributor = distributorControl.getDistributor(View);
}
public function setTargetModel(model:Model) {
this.model = model;
distributor.onTargetModelChanged(this);
}
public function getTargetModel(Void):Model {
return model;
}
}
new EventSupport()
public function addListener(listener):Void
Adds the passed-in listener
to be executed by events.
listener | the listener to add |
IllegalArgumentException | if the listener does not match any expected type |
public function addAllListeners(listeners:Array):Void
Adds all listener contained in the passed-in listeners
array.
All listeners get added after each other. If one listener does not match any expected type the rest of the listeners will not be added an a exception will raise.
listeners | the list of listeners to add |
IllegalArgumentException | if any listener does not match any expected type |
addAllListeners() in org.as2lib.env.event.EventListenerSource
public function removeListener(listener):Void
Removes the passed-in listener
from beeing executed by events.
listener | the listener to remove |
removeListener() in org.as2lib.env.event.EventListenerSource
public function removeAllListeners(Void):Void
Removes all listeners from beeing executed by events.
removeAllListeners() in org.as2lib.env.event.EventListenerSource
public function getAllListeners(Void):Array
Getter for the list of all added listeners.
This method returns a copy (not a reference) of the list of all added listeners.
list that contains all added listeners
getAllListeners() in org.as2lib.env.event.EventListenerSource