How commands are executed? (answer is:Command)

You can execute commands in 2 ways: directly and indirectly.

  • You can execute commands directly using commandMap object:
[as3] commandMap.execute(ClassOfCommand, new ParamVO());
[/as3]

Second parameter is optional and will be passed to execute function as parameter.
commandMap is accessible from your Module classes and other Command classes.

  • To execute commands indirectly you will need to use framework messages:

First you need to map Cammand class to message string.

[as3] commandMap.map("messageName", ClassOfCommand);
[/as3]

Then this is done, the only thing you need to do to get your Command executed – send a message. (Second parameter is optional and will be passed to execute function as parameter.)

[as3] sendMessage("messageName", new ParamVO());
[/as3]

You can send messages from all framework actors : Module, Cammand, Proxy, Mediator.

It’s good idea to store message string – “messageName” in a constant.
It is better practice to use messages to execute your command in almost all cases.
But there is some exceptions, for example if you don’t plan to reuse your command, or your command is tightly bundled with current command(or module) in the way that it does not make sense to use outside of it.