RL2 PopUp Mappings

mbarjawi's Avatar


08 Feb, 2013 08:25 AM


I just updated my RL2 library to the latest one. After sometime fixing some bugs here and there, everything now is working except for one thing. PopUps.

The way I am currently doing this is by calling a command that shows the popup. The command looks like this:

public function execute():void
    viewManager.addContainer( dialog );
    dialog.showPopUpCentered( parent, modal, null, moduleFactory );
    // above statement is same as: PopUpManager.addPopUp( this, parent, modal, childList, moduleFactory );

When I switched to the latest RL2, I started getting this error when I open the dialog for the first time:

Injector mapping override for type [class SkillGoalDialog] with name 
    at robotlegs.bender.extensions.vigilance::VigilanceExtension/mappingOverrideHandler()[Z:\www\FlexProjects\libs\robotlegs-framework\src\robotlegs\bender\extensions\vigilance\VigilanceExtension.as:61]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at org.swiftsuspenders.mapping::InjectionMapping/toProvider()[/Development/projects/SwiftSuspenders/src/org/swiftsuspenders/mapping/InjectionMapping.as:152]
    at org.swiftsuspenders.mapping::InjectionMapping/toValue()[/Development/projects/SwiftSuspenders/src/org/swiftsuspenders/mapping/InjectionMapping.as:127]
    at robotlegs.bender.extensions.mediatorMap.impl::MediatorFactory/mapTypeForFilterBinding()[Z:\www\FlexProjects\libs\robotlegs-framework\src\robotlegs\bender\extensions\mediatorMap\impl\MediatorFactory.as:158]
    at robotlegs.bender.extensions.mediatorMap.impl::MediatorFactory/createMediators()[Z:\www\FlexProjects\libs\robotlegs-framework\src\robotlegs\bender\extensions\mediatorMap\impl\MediatorFactory.as:75]
    at robotlegs.bender.extensions.mediatorMap.impl::MediatorViewHandler/handleView()[Z:\www\FlexProjects\libs\robotlegs-framework\src\robotlegs\bender\extensions\mediatorMap\impl\MediatorViewHandler.as:80]
    at robotlegs.bender.extensions.mediatorMap.impl::MediatorMap/handleView()[Z:\www\FlexProjects\libs\robotlegs-framework\src\robotlegs\bender\extensions\mediatorMap\impl\MediatorMap.as:93]
    at robotlegs.bender.extensions.viewManager.impl::ContainerBinding/handleView()[Z:\www\FlexProjects\libs\robotlegs-framework\src\robotlegs\bender\extensions\viewManager\impl\ContainerBinding.as:119]
    at robotlegs.bender.extensions.viewManager.impl::StageObserver/onContainerRootAddedToStage()[Z:\www\FlexProjects\libs\robotlegs-framework\src\robotlegs\bender\extensions\viewManager\impl\StageObserver.as:119]
    at flash.display::DisplayObjectContainer/addChildAt()
    at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::rawChildren_addChildAt()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:2130]
    at mx.managers::SystemManager/addChildAt()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:1753]
    at mx.managers::SystemManager/addChild()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:1736]
    at mx.managers::PopUpManagerImpl/addPopUp()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\PopUpManagerImpl.as:344]
    at mx.managers::PopUpManager$/addPopUp()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\PopUpManager.as:193]
    ......lots of other stuff here

And when I try to open the dialog for the second time, it says:

Injector is missing a mapping to handle injection into property "dialog" ...

When I remove the viewManager line, the dialog opens and its mappings work fine, but the inner views inside the popup don't have their mappings working.

Maybe it is also important to mention that this is a command, the dialog itself is injected into it as in the configuration files I map the dialog as:

injector.map( SkillGoalDialog ).asSingleton();
  • So I was wondering if I am doing this the right way.
  • In addition, is this wrong that I am mapping the dialog in the configuration files, and then using viewManager on it whenever the dialog is being opened?

Thanks for the help,

  1. Support Staff 1 Posted by Ondina D.F. on 08 Feb, 2013 10:34 AM

    Ondina D.F.'s Avatar

    Hi Barjawi,

    If it’s just a view without mediator, try this:

    var popUpView:PopUpView=injector.getOrCreateNewInstance(PopUpView);
    in your config, and then inject PopUpView into the command.

    I use it like this for a mediated popUpView:



    var titleWindowInstance: PopUpView = injector.getOrCreateNewInstance(PopUpView);
    PopUpManager.addPopUp(titleWindowInstance, FlexGlobals.topLevelApplication as DisplayObject);


  2. Support Staff 2 Posted by Shaun Smith on 08 Feb, 2013 08:52 PM

    Shaun Smith's Avatar

    Hi Barjawi,

    The problem is probably this line:

    injector.map( SkillGoalDialog ).asSingleton();

    If you have a mediator mapped to that class there will be a conflict. It's generally a bad idea to map views as singletons. Is there a reason that you need to do that?

  3. 3 Posted by mbarjawi on 08 Feb, 2013 10:25 PM

    mbarjawi's Avatar

    Thank you Shaun and Ondina for your replies.

    I am using behaviors in my project. So I have the following mappings in the configuration commands:

    mediatorMap.map( ISkillGoalItemSaveHandler ).toMediator( SkillGoalItemSaveHandlerMediator );
    injector.map( SkillGoalDialog ).asSingleton();

    and then the dialog itself implements the ISkillGoalItemSaveHandler.

    I had to map the SkillGoalDialog as a singleton so that inside the ShowSkillGoalDialogCommand I can inject it, and pop it up.

    Now inside the dialog itself, I have two other views, both of which implement other behaviors as well.

    I was mistaken above to say that the dialog get its mediator to work but the inner views that have problems. I just found out that neither the dialog nor the inner views get their mediators to run when I remove the "addContainer" function.

    Thanks for all the help,

  4. 4 Posted by mbarjawi on 08 Feb, 2013 10:28 PM

    mbarjawi's Avatar

    I just want to mention that this error used to occur with the previous RL2 version, however it was always logged, and I ignored it because everything seems to be working fine.

    However, with the new version of RL2, the VigilanceExtension is throwing an error because of this logged error.

    I always wanted to know why this error shows up, but didn't have time to post about it. :) now it came back to me.

  5. 5 Posted by mbarjawi on 10 Feb, 2013 05:25 AM

    mbarjawi's Avatar

    I created a test project to test this problem. Please take a look at RL2DialogMapping. This project is compiled using Flash Builder 4.7, Apache Flex 4.9, the latest RL2 (in master branch), as3-Signals, and the latest SignalCommandMap.

    • You will see two comments, // Test 1 and // Test 2 in two files: RL2DialogMappingConfig.as and RL2DialogMapping.mxml.
    • Currently // Test 2 is uncommented in both files.
    • If you run the application, then click the button to show the popup, an error will show that is similar to the error mentioned in the first post of this thread.
    • Click on "continue" on the Flash Player Error dialog, the dialog will still show up.
    • If you close the dialog, then click on the button again to open the popup again, you will get a different error stating that the dialog injection is missing and the command cannot be called.
    • This second error is very strange to me because the dialog is mapped as singleton, and there is no place in the code where I remove the mapping. So I guess it is the viewManager that does this, but I am not sure.

    So this is in short my problem. I hope someone can help me figure out what am I doing wrong here.

    • Now, if you comment // Test 2 lines, and uncomment // Test 1, and try again, everything will work smoothly.

    I don't like the method used in // Test 1 because you have to create a new instance of the dialog every time it is opened. I want this to work in a way that the dialog is created one time, then used as much as required. One of my dialogs is big, opening it for the first time is a bit slow. Having it in memory and opening it for second time, it opens much smoother.

    Come to think about it, I don't know if keeping a dialog in memory is a good idea or not. But this is what I have been doing so far.

    I am open to any recommendations and best practices, so please let me know which way is the preferred way of opening dialogs in RL2.

    Finally, any comments about the way I structure the project are also welcome. Its a quick project, but I made sure to prepare it in the way I always use for my projects.

    Thanks for the help.

  6. Support Staff 6 Posted by Ondina D.F. on 10 Feb, 2013 08:42 AM

    Ondina D.F.'s Avatar

    I'm taking a look at your code now.

  7. Support Staff 7 Posted by Ondina D.F. on 10 Feb, 2013 12:06 PM

    Ondina D.F.'s Avatar

    Sorry for the delay, but, you now, it’s Sunday…and time flows differently than during the week :)

    As Shaun pointed out, it might not be a good idea to map a view as a singleton.

    I don’t know if it is what you want, but you could do this, if you really wanted to:

    In the config: _injector.map( MyDialog ).asSingleton();


    public var viewManager:IViewManager;
    public var dialog:MyDialog;
    public var contextView:ContextView;
    public var injector:Injector;
    public function execute():void
    viewManager.addContainer( dialog );
    PopUpManager.addPopUp( dialog, contextView.view );
    PopUpManager.centerPopUp( dialog );

    Let me know if this is working for you and if it is what you needed.

    More explanations later today, or tomorrow..

  8. Support Staff 8 Posted by Shaun Smith on 10 Feb, 2013 02:19 PM

    Shaun Smith's Avatar

    Hi Barjawi,

    To understand what's going wrong you need to understand how the framework deals with Mediators (the same concept applies to Commands btw).

    If you map TypeX to MediatorX, and then add an instance of TypeX to the stage, the mediator map does this (roughly):

    1. Map TypeX to the actual instance that landed on stage
    2. Use the injector to create an instance of MediatorX
    3. Unmap TypeX from the instance that landed on stage

    Step 1 exists so that the view instance is available for injection into the mediator. Step 3 is there to clean up that mapping.

    This why you're running into problems. When step 1 runs there is a mapping override. When step 3 runs the mapping is destroyed.

    Mapping your view as a singleton creates an unreasonable situation. You're saying that there should only be a single instance of TypeX, but that cannot be enforced. Anyone could add a different instance of TypeX to the stage. If we did not perform the steps above, you could imagine this happening:

    1. The singleton mapping enforces a single instance of TypeX. Let's call that instance `viewA`.
    2. A different instance is added to the stage. Let's call that instance `viewB`
    3. A mediator is created for `viewB`, but instead of being injected with `viewB`, it is injected with `viewA`.

    This is why you shouldn't map view components into the injector. View instances (by their nature) are not singletons.

    If you want to cache your view as a Singleton (big S), then there is a more compatible way to do that. Instead of mapping it as singleton in the injector, create a static variable somewhere:

    dialog = DialogCache.getSkillGoalDialog();

    The DialogCache might look like this (pseudo-code):

    class DialogCache
        private static var:skillGoalDialog;
        public function getSkillGoalDialog():SkillGoalDialog
            return skillGoalDialog ||= new SkillGoalDialog();

    Hope that clears things up a little.

  9. 9 Posted by mbarjawi on 11 Feb, 2013 11:08 PM

    mbarjawi's Avatar

    Thank you all for your help. I appreciate it so much.

    I think you are correct. I shouldn't be having those dialogs as singletons. I fixed this by creating a new instance of the dialog each time the command is called to open the dialog.

    Thanks for the help,

  10. mbarjawi closed this discussion on 11 Feb, 2013 11:09 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