Module mapView not firing

simon's Avatar


12 Apr, 2011 10:04 AM

Hi All,

I am pretty sure this is some sort of race condition issue but could do with some fresh eyes on this. I have a Flex RL application using Strays modular utility, one reason is I am not using Flex modules i.e. mx:Module.

The problem is everything fires as I would expect i.e. Context starts up, View is added to the stage and Module Mediator fires onRegister(), my View has a nested component which has its own Mediator e.g. MyNestedComponentMediator.

Problem is a view mapping defined in the ModuleContext is not firing onRegister()?

Here is my workflow to make it clearer what I am doing here:

1) I have modified slightly the org.robotlegs.utilities.modular.mvcs.ModuleContextView by adding a getter/setter for a view which extends SkinnableContainer. This is so that when I add a new module to the display list I can use addElement and provide a skinnable interface.

    public class ModuleContextView extends Sprite implements IModuleContextView
    protected var context:ModuleContext;
            private var _view:SkinnableContainer;

    public function ModuleContextView()

    public function setModuleDispatcher(dispatcher:IModuleEventDispatcher):void

    public function startup():void

    public function getModuleContext():ModuleContext{
        return context;

    public function get view():SkinnableContainer
        return _view;

    public function set view(value:SkinnableContainer):void
        if(this.contains(_view)) this.removeChild(_view);

2) A module manager starts up the module:

    public function integrateModules(modulesList:Vector.<ModuleContextView>, viewContainer:SkinnableContainer):void
        trace("ADD THE MODULES");
        var nextModule:ModuleContextView;

        for each (nextModule in modulesList)

3) Module assigns context and creates the (SkinnableContainer) view:

    public function MyDisplayModule()
        context=new MyDisplayModuleContext(this);
        context.addEventListener(ContextEvent.STARTUP_COMPLETE, initView);

    protected function initView(e:ContextEvent):void
        trace("MyDisplayModule::Add MyDisplay view");
        this.view=new MyDisplay();

4) Within the MyDisplayModuleContext onStartup() I then map my views:

mediatorMap.mapView(MyComponent, MyComponentMediator);

5) MyDisplay has the component MyComponent in its display list:

    <?xml version="1.0" encoding="utf-8"?>
<view:MyComponent id="myComponent"/>

This traces out in the following order:

  • [trace] ADD THE MODULES
  • [trace] MyDisplayModuleContext::startup
  • [trace] onRegister in MyDisplayModuleMediator
  • [trace] MyDisplayModule::Add MyDisplay view
  • [trace] Added MyComponent to stage

So as you can see the actual module mediator is firing the onRegister() fine but although the MyComponent view mapping is showing in the contexts mediatorMap::mappingConfigByViewClassName the MyComponentMediator does not seem to be getting instantiate and thus firing its onRegister().

Anyone got any thoughts as to where I am synchronising startup incorrectly here?

  1. Support Staff 1 Posted by creynders on 12 Apr, 2011 11:28 AM

    creynders's Avatar

    Do you call super.startup in MyDisplayModuleContext.startup before mapping MyComponent to MyComponentMediator?
    Because it will send out a ContextEvent.STARTUP_COMPLETE event, which in this case means the component gets added to the display list before it's mapped to its mediator.

  2. 2 Posted by simon on 12 Apr, 2011 11:58 AM

    simon's Avatar

    Hi @creynders, this the order of events (I just verified debugging to make sure):

    • Module created >
    • ModuleContext::startup() >
    • TemplateDisplayModuleContext::startup() >
    • MyComponent to MyComponentMediator mapped >
    • TemplateDisplayModuleContext::super.startup() >
    • new instance of MyDisplay() created >
    • new instance of MyDisplay() gets added to the stage.
  3. Support Staff 3 Posted by creynders on 12 Apr, 2011 12:56 PM

    creynders's Avatar

    Looking at your code snippets again I think maybe the display list the view gets added to is not the display list that the modulecontext is listening to for the ADDED_TO_STAGE events.
    In MyDisplayModule

    context=new MyDisplayModuleContext(this);

    you pass 'this' to the context, which means it will listen to the displaylist of MyDisplayModule, but the component is added to the viewContainer with


    My guess is that's where it goes wrong?
    That it gets added "above" MyDisplayModule instead of inside.

  4. 4 Posted by simon on 12 Apr, 2011 01:08 PM

    simon's Avatar

    My doubts lay in the same area, fresh eyes are always mega helpful mate thanks, I will look deeper. What I was trying to avoid was having to start editing ModuleContextView further for this.

  5. 5 Posted by Amy Blankenship on 21 Apr, 2011 12:24 AM

    Amy Blankenship's Avatar

    You may also want to think about whether your contexts that get created in Step 3 get garbage collected before they are used.

  6. Support Staff 6 Posted by Stray on 02 May, 2011 03:35 PM

    Stray's Avatar

    Closing this as I know you've now fixed it. Feel free to reopen it if you need more follow-up.


  7. Stray closed this discussion on 02 May, 2011 03:35 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