org.as2lib.core.BasicInterface +--org.as2lib.env.event.EventListenerSource +--org.as2lib.env.event.impulse.Impulse
Impulse
is a definition for events that gets executed periodically.
Periodical events could be frame executions, seconds, hours or dates.
Impulse
allows to seperate the certain kind of Impulse from the
execution code.
The Impulse
executes Executable.execute on each impulse to
the connected executables.
Example:
import org.as2lib.env.event.impulse.Impulse;
import org.as2lib.env.event.impulse.FrameImpulse;
import org.as2lib.app.exec.Call;
function test(impulse:Impulse) {
trace(impulse+" executed at "+getTimer()+"ms");
}
var impulse:Impulse = FrameImpulse.getInstance();
impulse.connectExecutable(new Call(this, test));
Additionally its possible to work with the impulse as EventListenerSource.
With you can add ImpulseListener implementations
as listener to the code.
Listener:
import org.as2lib.env.event.impulse.ImpulseListener;
import org.as2lib.env.event.impulse.Impulse;
class TraceImpulseListener implements ImpulseListener {
public function onImpulse(impulse:Impulse):Void {
trace(impulse+" executed at "+getTimer()+"ms");
}
}
Test:
import org.as2lib.env.event.impulse.Impulse;
import org.as2lib.env.event.impulse.FrameImpulse;
var impulse:Impulse = FrameImpulse.getInstance();
impulse.addImpulseListener(new TraceImpulseListener());
The addListener referes to eighter or to depending to what kind of listener you pass. If you pass a not-matching impulse it will throw a IllegalArgumentException.
addAllListeners(), addListener(), getAllListeners(), hasListener(), removeAllListeners(), removeListener()
public function addImpulseListener(listener:ImpulseListener):Void
Adds a ImpulseListener for listening to the onImpulse event to the Impulse.
listener | Listener to be added. |
public function removeImpulseListener(listener:ImpulseListener):Void
Removes a added ImpulseListener from listening to the onImpulse event.
If the certain listener also implements other event types it will also be remove from listening to those events.
listener | Listener to be added. |
public function addAllImpulseListeners(listener:Array):Void
Adds a list of ImpulseListeners as listener to the events.
IllegalArgumentException | if one listener didn't match to any listener type. |
public function getAllImpulseListeners(Void):Array
Getter for the list of all added ImpulseListeners.
List that contains all added listeners.
public function hasImpulseListener(listener:ImpulseListener):Boolean
Checks if the listener
has been added.
listener | Listener to be checked if it has been added. |
True if the certain listener has been added.
public function removeAllImpulseListeners(Void):Void
Removes all added ImpulseListeners from listening to any event.
public function connectExecutable(executable:Executable):Void
Connect a certain executable to listen to the continous event.
executable | Executable that should be connected |
public function connectAllExecutables(executables:Array):Void
Connects a list of Executables to be executed on the continous event.
executables | List of Executables to be added. |
public function getAllConnectedExecutables(Void):Array
Getter for the list of all connected Executables.
List that contains all connected executables.
public function disconnectExecutable(executable:Executable):Void
Disconnect a certain executable from listening to the Impulse
.
executable | Executable that should be disconnected |
public function isExecutableConnected(executable:Executable):Boolean
Checks if a certain Executable has been added as listener.
executable | Executable to be checked if it has been added. |
True if the certain listener has been added.