O'Reilly logo

Professional Cairngorm™ by Jeremy Wischusen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

24.1. The SequenceCommand Class

The makers of Cairngorm took into account that you might want to trigger sequences of commands. In the com.adobe.cairngorm.commands package you can find a class named SequenceCommand.

This class contains a property named nextEvent that holds an instance of a Cairngorm event. You can fire this event by calling the executeNextCommand method.

To use the SequenceCommand class you have your command class extend it, as in the following, rather than simply implementing the ICommand interface:

package com.FlexBlog.commands
{
    import com.adobe.cairngorm.commands.SequenceCommand;
    import com.adobe.cairngorm.control.CairngormEvent;
    import com.FlexBlog.events.SomeEvent;
    import mx.rpc.IResponder;

    public class ExampleSequenceCommand extends SequenceCommand
implements IResponder
    {
        public function ExampleSequenceCommand()
        {
           this.nextEvent = new SomeEvent(SomeEvent.SOME_CONSTANT);
        }
        override public function execute(event:CairngormEvent):void{
            //call some function on a delegate.
        }
        public function result(data:Object):void
        {
            //if all goes well, execute the next command
            this.executeNextCommand();
        }
        public function fault(info:Object):void
        {
        }
    }
}

Note one thing: now that you are extending a class rather than implementing the ICommand interface, you have to override the execute method. Also note that you are now defining a constructor that sets the nextEvent property by creating the appropriate event. This event is then triggered in the result function by calling the executeNextCommand ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required