Sequencing multiple commands

24 December, 2006

In your cairngorm Flex 2 application you may require to string a sequence of commands together. This may occur in your application’s initialization process or in the view from a user gesture.

For example, in the case of an e-commerce application on initialization you may be required to get all categories, sub-categories related to a category and the products related to a sub-category all in one process.

In cairngorm each command requires an event to be fired in order to execute the command. Now where you create that next event to be fired is usually in the subsequent command, prior to setting it to that command’s nextEvent property.

Perhaps this approach may not be suitable depending on your commands (as in one my cases) so i created a utility for chaining events together so that a sequence of events can be fired at the developer’s desire.

To demonstrate a scenario of the usage of this utility i have created a small example (click here and right-click to download source) and an illustration of the example.

Event Chaining Diagram

What i’ve done is create a sub-class of CairngormEvent which has a public property called nextChainedEvent.
Then I’ve create a utility class called EventChainFactory with a method chainEvents, which accepts an array of ChainEvent instances as its only parameter with each event in the array ordered in the order you want your sequence of events fired in. The method returns a ChainEvent instance with each subsequent event set to the next event’s nextChainedEvent property.

Enjoy and dont hestitate to improve it.

Bjorn Schultheiss


7 Responses to “Sequencing multiple commands”

  1. Hey Bjorn,
    I think your code is week, and your name is that of a tinker bell. You cant handle the Refactor. Do yourself a favor like your Aussie Mate and go swim with some sting rays and leave the Flex-in to The Ceaser. Check the shoulder,

    The Flex Ceaser

  2. tinker bell…
    my code is weak…
    cant handle the refactor!!!

    Marco yeah your flex-in, yeah your doing your thing on your thrown.

    But there’s some new wiz kids coming up the ranks. I’m just getting started here… You’ve been at this for years, but now you’ve become a target.. I’m coming for you, i’m comin for the thrown and i’ll see you soon.


    Alien Science (i’m dropping tinkerbell)

  3. You might want to check the new alfa version of our framework for sequences implementation in AS 3 and this article that explains the ideas behind them

  4. naisioxerloro Says:

    Good design, who make it?

  5. Bjorn Says:

    me, thanks : )


  6. Karen Duke Says:

    Good site, I’m looking for new writers for my site which is play flash games online to make it bigger and better so shoot an email please.

  7. Karen Duke Says:

    Hey I was browsing for designs on my site download flash games online because I need a really good template since this site will be big someday, send me a pm on where you got that design.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: