Class org.as2lib.env.event.multicaster.SimpleConsumableEventMulticaster

org.as2lib.core.BasicClass
   +--org.as2lib.env.event.SimpleEventListenerSource
      +--org.as2lib.env.event.multicaster.SimpleConsumableEventMulticaster

Implemented Interfaces

ConsumableEventMulticaster

Description

SimpleConsumableEventMulticaster multicasts an event to all added listeners with custom arguments until the event is consumed.

Example: // creates a multicaster for the 'onError' event var multicaster:SimpleConsumableEventMulticaster = new SimpleConsumableEventMulticaster("onError"); // adds listeners multicaster.addListener(new SimpleErrorListener()); multicaster.addListener(new MyErrorListener()); // executes the specified event on all listeners passing the given arguments multicaster.dispatch(myErrorCode, myException);

The event dispatch is stopped as soon as any of the above listeners returns true. If for example the SimpleErrorListener.onError method returns true, MyErrorListener.onError will not be executed because the event is consumed.

Method Index

new SimpleConsumableEventMulticaster()

dispatch(), getEventName()

Inherited from SimpleEventListenerSource

addAllListeners(), addListener(), getAllListeners(), hasListener(), removeAllListeners(), removeListener()

Inherited from BasicClass

toString()

Constructor Detail

SimpleConsumableEventMulticaster

public function SimpleConsumableEventMulticaster(eventName:String, listeners:Array)

Constructs a new SimpleConsumableEventMulticaster instance.

Parameters

eventNamethe name of the event to execute on listeners
listeners(optional) an array of listeners to populate this broadcaster with

Throws

IllegalArgumentExceptionif passed-in eventName is null, undefined or an empty string

Method Detail

getEventName

public function getEventName(Void):String

Returns the event name set on construction.

Return

the name of the event

dispatch

public function dispatch():Void

Dispatches the event to all listeners passing the given arguments as parameters to the listeners' event methods until a listener consumes the event by returning true.

Parameters

...any number of arguments to pass to the listeners' event methods

Throws

EventExecutionExceptionif a listener's event method threw an exception