An AIR 3.7 application demonstrating the use of multiple Contexts with the Robotlegs AS3 micro-architecture - version 2
WIP
In this demo the Shell loads 2 (Flex) Modules, Module_A and Module_B, and a popup window (Flex TitleWindow), which also loads a module, Module_C.
The Contexts communicate with each other through 2 ‘channels’, a named channel 'A-and-B', and a default channel.
The steps for enabling the multi contextual communication:
First of all, you need a contextView, a Context and the ModularityExtension (included in the MVCSBundle).
Let’s look at Module A’s root Display Object Container ModuleAView, which will be used as the "contextView" for this Context.
private var _robotlegsContext:ModuleAContext;
private function creationCompleteHandler(event:FlexEvent):void
{
_robotlegsContext = new ModuleAContext(this);
}
public function ModuleAContext(view:DisplayObjectContainer)
{
context = new Context() //1
.install(MVCSBundle) //2
.configure(MediatorsConfig, ModuleConnectorConfig) //3
.configure(new ContextView(view)); //4
}
- creates a Context
- installs the ModularityExtension (included in the MVCSBundle already)
- configures the communication channels (ModuleConnectorConfig)
moduleConnector.onDefaultChannel()
.receiveEvent(ModularConnectorEvent.SHELL_TO_MODULES_MESSAGE);
moduleConnector.onChannel('A-and-B')
.relayEvent(ModularConnectorEvent.A_TO_B_MESSAGE);
moduleConnector.onChannel('A-and-B')
.receiveEvent(ModularConnectorEvent.B_TO_A_MESSAGE);
- provides a contextView (ModuleAView)
- dispatch events to other Contexts
dispatch(new ModularConnectorEvent(ModularConnectorEvent.A_TO_B_MESSAGE, event.messagesVO));
- listen to events from other Contexts
addContextListener(ModularConnectorEvent.B_TO_A_MESSAGE, onMessageReceived, ModularConnectorEvent);
To be continued...