Packageorg.springextensions.actionscript.cairngorm
SVN browsingEventSequence.as
FisheyeEventSequence.as
Classpublic class EventSequence

An EventSequence represents a sequence of events to be chained. This allows you to chain commands by chaining the events that are dispatched to the FrontController in order to execute a command. Alternatively, basic Events may also be part of the sequence by specifying an event dispatcher when the events are queued.

Using an event sequence, the commands do not have to extend SequenceCommand and hence do not have to set up a nextEvent and dispatch it. This means that your commands can be used in a number of different sequence scenarios without letting the commands know they are chained.

The sequencing works by setting up a trigger for an event, based on a property change in an object. This property change will normally be executed by a command.


Example
The following example sets up an event sequence and dispatches it:
var sequence:EventSequence = new EventSequence();
      sequence.addSequenceEvent(LoadSessionEvent, ["4562-54289778-56985412"]);
      sequence.addSequenceEvent(LoadExamEvent,
    [new Property(ModelLocator.getInstance(), "session", "examId")],
    [new Property(ModelLocator.getInstance(), "session")]);
      sequence.addSequenceEvent(LoadCandidateEvent,
    [new Property(ModelLocator.getInstance(), "session", "candidateId")],
    [new Property(ModelLocator.getInstance(), "exam")]);
      sequence.dispatch();

In this example, 3 events are chained. (This sequence is used to load the session of an exam, the exam itself and the candidate)

The first event is the LoadSessionEvent that gets the id of a session as its constructor argument. The command that is executed by this event will fetch an exam session and store it in the session property of the ModelLocator. Since this is the first event, it does not define any triggers for the next event.

The second event is the LoadExamEvent. This event takes the id of the exam as its constructor argument, fetches an exam and stores it in the exam property of the ModelLocator. Notice the 3rd argument that defines the trigger for this event. It is defined a Property object that contains a reference to the session property in the ModelLocator. This means that this event will be dispatched when the session property has been set. The examId is also passed in as a property and will be evaluated when the sequence creates the next event.

The third event is the LoadCandidateEvent. This event takes the session.candidateId as its constructor argument and will be dispatched when the exam property is set on the ModelLocator.

Authors: Christophe Herreman, Tony Hillerson, Jürgen Failenschmid
Version: $Revision: 21 $, $Date: 2008-11-01 22:58:42 +0100 (za, 01 nov 2008) $, $Author: dmurat $
Since: 0.1



Documentation reference: event sequences


Public Methods
 MethodDefined by
  
EventSequence(eventDispatcher:IEventDispatcher = null)
Creates a new EventSequence
EventSequence
  
addSequenceEvent(eventClass:Class, parameters:Array = null, triggers:Array = null):void
Adds a Cairngorm event to this sequence.
EventSequence
  
addWithDispatcher(dispatcher:IEventDispatcher, eventClass:Class, parameters:Array = null, triggers:Array = null):void
Adds a basic event to this sequence.
EventSequence
  
cancel():void
In case of failure, this cancels the 'on deck' sequence
EventSequence
  
dispatch():void
Starts dispatching this event sequence.
EventSequence
Protected Methods
 MethodDefined by
  
calculateTriggers(event:Event, nextEvent:SequenceEvent):Array
Determines the conditions that trigger the argument nextEvent.
EventSequence
Constructor detail
EventSequence()constructor
public function EventSequence(eventDispatcher:IEventDispatcher = null)

Creates a new EventSequence

Parameters
eventDispatcher:IEventDispatcher (default = null)
Method detail
addSequenceEvent()method
public function addSequenceEvent(eventClass:Class, parameters:Array = null, triggers:Array = null):void

Adds a Cairngorm event to this sequence.

Parameters
eventClass:Class — the class of the event (must be a subclass of CairngormEvent)
 
parameters:Array (default = null) — the arguments that will be passed to the event's constructor
 
triggers:Array (default = null) — the triggers that will cause the next event to be dispatched
addWithDispatcher()method 
public function addWithDispatcher(dispatcher:IEventDispatcher, eventClass:Class, parameters:Array = null, triggers:Array = null):void

Adds a basic event to this sequence.

Parameters
dispatcher:IEventDispatcher — the source of the event
 
eventClass:Class — the class of the event (must be a subclass of Event)
 
parameters:Array (default = null) — the arguments that will be passed to the event's constructor
 
triggers:Array (default = null) — the triggers that will cause the next event to be dispatched
calculateTriggers()method 
protected function calculateTriggers(event:Event, nextEvent:SequenceEvent):Array

Determines the conditions that trigger the argument nextEvent. These may depend on the two argument events.

Parameters
event:Event — the event that will be dispatched
 
nextEvent:SequenceEvent — A description of the next event in the sequence. It may specify triggers.

Returns
Array — An array of event triggers, or null

See also

cancel()method 
public function cancel():void

In case of failure, this cancels the 'on deck' sequence

dispatch()method 
public function dispatch():void

Starts dispatching this event sequence.