PureMVC AS3 Framework - [Standard Version] | All Packages | All Classes | Index | Frames No Frames |
Class MacroCommand

Package | org.puremvc.as3.patterns.command
Class | public class MacroCommand
Inheritance | MacroCommand Notifier
Implements | ICommand, INotifier

A base `ICommand` implementation that executes other `ICommand`s.

A `MacroCommand` maintains an list of `ICommand` Class references called SubCommands.

When `execute` is called, the `MacroCommand` instantiates and calls `execute` on each of its SubCommands turn. Each SubCommand will be passed a reference to the original `INotification` that was passed to the `MacroCommand`'s `execute` method.

Unlike `SimpleCommand`, your subclass should not override `execute`, but instead, should override the `initializeMacroCommand` method, calling `addSubCommand` once for each SubCommand to be executed.

See also

Controller
Notification
SimpleCommand

Protected Properties
Hide Inherited Protected Properties
Show Inherited Protected Properties

| Property | Defined by
--- | --- | ---
|  | facade : IFacade | Notifier

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined by
--- | --- | ---
|  | MacroCommand() Constructor. | MacroCommand
|  | execute(notification:INotification):void Execute this `MacroCommand`'s SubCommands. | MacroCommand
|  | sendNotification(notificationName:String, body:Object = null, type:String = null):void Create and send an `INotification`. | Notifier

Protected Methods

| Method | Defined by
--- | --- | ---
|  | addSubCommand(commandClassRef:Class):void Add a SubCommand. | MacroCommand
|  | initializeMacroCommand():void Initialize the `MacroCommand`. | MacroCommand

Constructor detail

MacroCommand | () | constructor

`public function MacroCommand()`

Constructor.

You should not need to define a constructor, instead, override the `initializeMacroCommand` method.

If your subclass does define a constructor, be sure to call `super()`.

Method detail

addSubCommand | () | method

`protected function addSubCommand(commandClassRef:Class):void`

Add a SubCommand.

The SubCommands will be called in First In/First Out (FIFO) order.

Parameters

| `commandClassRef:Class` — a reference to the `Class` of the `ICommand`.

execute | () | method |

`public final function execute(notification:INotification):void`

Execute this `MacroCommand`'s SubCommands.

The SubCommands will be called in First In/First Out (FIFO) order.

Parameters

| `notification:INotification` — the `INotification` object to be passsed to each SubCommand.

initializeMacroCommand | () | method |

`protected function initializeMacroCommand():void`

Initialize the `MacroCommand`.

In your subclass, override this method to initialize the `MacroCommand`'s SubCommand list with `ICommand` class references like this:

        // Initialize MyMacroCommand
        override protected function initializeMacroCommand( ) : void
        {
         addSubCommand( com.me.myapp.controller.FirstCommand );
         addSubCommand( com.me.myapp.controller.SecondCommand );
         addSubCommand( com.me.myapp.controller.ThirdCommand );
        }

Note that SubCommands may be any `ICommand` implementor, `MacroCommand`s or `SimpleCommands` are both acceptable.