Cairngorm – Chain Events
Found an Example of Chain Events at http://www.cairngormdocs.org/bjorn_schultheiss/eventChaining/EventChainExample.html (right click and check source).
So I put the code to an default Cairngorm Structure that you can download here. Just make sure that you have the Cairngorm.swc package in libs.
This is what files that exist.
Important to think of:
1.) All events extends ChainEvent
public class TestAEvent extends ChainEvent
2.) All commands extends SequenceCommand
public class TestACommand extends SequenceCommand implements ICommand
3.) All commands take the nextEvent and execute when done.
override public function execute(event:CairngormEvent):void { nextEvent = ChainEvent(event).nextChainedEvent; // Do Command Action this.executeNextCommand(); }
That’s is…
Here is an example of executing a couple of commands.
var beginChain : ChainEvent = EventChainFactory.chainEvents([ new UpdateViewEvent(ModelData.VIEW_LOADING), new CheckSoftwareVersionEvent(), new GetLocalSettingsEvent(), new GlobalApplicationEvent(), new GetFeedListEvent(), new UpdatePostStatusEvent(), new UpdateViewEvent(ModelData.VIEW_POSTS) ]); cgDispatcher.dispatchEvent( beginChain );
————–
UPDATE: 2008-02-21
I’ve added a couple of changes for the demo files.
E.g. when creating an event it’s possible to send custom data
new TestAEvent( “CustomValue” )
and it’s just as easy to extract it in the command
var customEventValue:* = event.data;
You can add any data to the next event in the chain from the command, maybe to pass forward the data or something new. Here is an example.
nextEvent.data = customEventValue;You can as well runtime change the next event from a command, here is an example.
nextEvent = new TestCEvent();
