Problems picking up events using the modular shared event dispatcher

jeremy.brooks's Avatar


19 Apr, 2012 10:42 AM


I am developing a modular application that is made up of 3 main parts:

1) Core application, dictates which modules load etc.
2) Library which contains a module that is loaded by the core at runtime.
3) Multiple other modules (separate swf's) that are loaded depending on the cores requirements at runtime.

My problem is that I cant seem to pick up events dispatched onto the module shared event dispatcher in my library commands.

So to simplify, when I run my app, it starts ok, but when I "dispatchToModules" the event that should be picked up by a command that is in the library modules context, nothing happens. I have tested dispatching the event within the local context of the command, which works fine, any thoughts?

Here are the core parts of code that do the work:

Core's main view mediator:

public class TestWrapperMediator extends ModuleMediator
    public var view:TestWrapper;

    override public function onRegister():void{
        addViewListener(MouseEvent.CLICK, mapModuleReadyNowLoadMap);

    private function mapModuleReadyNowLoadMap(event:Event):void{
        dispatchToModules(new ChangeMapAPIEvent(ChangeMapAPIEvent.CHANGE_MAP_API_MODULE, "MapModule.swf"));

Library module's context:

public class MapAPIModuleContext extends ModuleContext
    public function MapAPIModuleContext(contextView:DisplayObjectContainer=null, autoStartup:Boolean=false, parentInjector:IInjector=null, applicationDomain:ApplicationDomain=null){
        super(contextView, autoStartup, parentInjector, applicationDomain);

    override public function startup():void{
        //map view class type, required for correct injection of modules.

        moduleCommandMap.mapEvent(ChangeMapAPIEvent.CHANGE_MAP_API_MODULE, MapAPIModuleChangeCommand);

Core library's command:

public class MapAPIModuleChangeCommand extends ModuleCommand
    public var event:ChangeMapAPIEvent;

    override public function execute():void{
        var module:IModuleInfo = ModuleManager.getModule(event.mapModuleUrl);
        dispatchToModules(new MapAPIModuleLoadCompleteEvent(MapAPIModuleLoadCompleteEvent.MAP_MODULE_LOADED_SUCCESSFULLY, module));

Additional info: I am overriding the clone method in all of my custom events.

Thanks for any advice.

  1. 1 Posted by jeremy.brooks on 19 Apr, 2012 11:48 AM

    jeremy.brooks's Avatar

    Ok guys, after some pair programming the problem has been solved. It turns out that to dispatch onto the module shared event dispatcher, the component that everything hinges off must implement IModule.

    Now I know that this is very clear in Joel Hooks examples:

    But the component I wanted to communicate with was just a "wrapper" for my modules, and didn't technically need to be a module itself. I had been using a simple canvas to load modules into. As soon as I made that component implement IModule, and extend Module, everything wired together as expected.

    It would be interesting to know if there is a way of picking up events between contexts without having to do this?

  2. 2 Posted by Stray on 19 Apr, 2012 11:59 AM

    Stray's Avatar

    Hi Jeremy,

    I'm glad you found the answer - 2 brains always best for this kind of thing, I find.

    If you take a look under the hood at the code in the original Modular extensions - on my fork - you'll find that wiring a shared dispatcher up is really easy. If you don't want to share injections between modules then that's actually all you need to do.



  3. 3 Posted by jeremy.brooks on 19 Apr, 2012 12:05 PM

    jeremy.brooks's Avatar

    Thanks for the info Stray, I'll take a look.

  4. Ondina D.F. closed this discussion on 19 Apr, 2012 02:29 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac