Mediators do not map when View is on multiple stages in AIR

stevensacks's Avatar


14 Apr, 2010 04:54 AM

I've run into a tough bug I cannot figure out what's wrong.

I'm using almost identical code to the WheresWindow example, where you call mediatorMap.createMediator(window);

View is mediated correctly when I addChild() an instance in a new native window without an instance of View being on another native window's stage. When a mediated view exists on both stages at once, there's an issue where the second one won't get mediated.

Simple description:

I've got a ViewMediator and a View.

I create a new NativeWindow and manually createMediator as the example shows. I instantiate View and addChild() it to the first NativeWindow's stage. and its mediator's onRegister gets called. Great, it works.

I then instantiate a new View, addChild() it to a new NativeWindow's stage using the same code as above, but its mediator's onRegister never fires.

View is not a mapped as a singleton (nor should it be).

  1. Support Staff 1 Posted by Joel Hooks on 14 Apr, 2010 06:31 AM

    Joel Hooks's Avatar

    WheresWindow is an example of using a Model (Proxy) to track instances of identical mediated objects. It wasn't meant to be AIR best practices or represent how to approach AIR based RL projects. That example should exist. It just doesn't yet.

    Windows are not DisplayObjects, and why it allows for auto-magic mediation in the first window and not later windows is anybody's guess. I'm sure there is a very logical technical reason for it. Off the top of my head there are a couple of solutions to this problem in the near term:

    • Mediate views within your windows manually. This might take some effort, and would probably lend itself to the creation of a tool of some sort.
    • Create a context for your windows. With the forthcoming addition of child injectors, this might become the more attractive option. Windows would communicate through the main window context.

    I'm sure there are other solutions. It isn't really a bug with the demo or RL though, just the nature of AIR windows. I haven't explored it in any depth, but the good news is that you are only really losing the magical mediation (and I've never been a fan of that anyway! ;) ) Maybe somebody else will chime in with a simple elegant solution or to tell me that I'm full of it. I know Swiz has issues with Windows as well.

  2. 2 Posted by stevensacks on 14 Apr, 2010 06:43 AM

    stevensacks's Avatar

    Let me be more specific.

    Here is a simplified version of my code. I have a Window class that has a WindowMediator that it's mapped to. The Window Sprite adds itself to the NativeWindow's stage after waiting 1 frame (for RobotLegs' createMediator to be ready), and then everything works. I can create multiple Window instances added to NativeWindows and they all work. What I cannot do is have a mediated view inside of one Window AND inside of another Window. The view appears, but its mediator doesn't fire, even though I wait one frame.

    public Window class extends Sprite

    private var _nativeWindow:NativeWindow;
    public function Window(nw:NativeWindow)
        _nativeWindow = nw;
        addEventListener(Event.ENTER_FRAME, onDelayAddChildForMediator);
    private function onDelayAddChildForMediator(event:Event):void 
    removeEventListener(Event.ENTER_FRAME, onDelayAddChildForMediator);


  3. Support Staff 3 Posted by Joel Hooks on 14 Apr, 2010 07:17 AM

    Joel Hooks's Avatar

    You can wait forever and the mediatorMap is not going to automatically mediate the views within your additional Windows (as it currently exists).


    Feel free to send me a non-simple version of what you are working on and I can give you my thoughts. That snippet above doesn't do much for me ;)

  4. Support Staff 4 Posted by Shaun Smith on 16 Apr, 2010 03:17 PM

    Shaun Smith's Avatar

    The issue here is that the MediatorMap can only listen to one display list at a time. Each AIR window has its own stage, so auto mediation doesn't work. Once you're in a new window, you have to manually create every mediator that you need for that window with mediatorMap.createMediator(view). It's sucky, we know. We'll address this with RL v2 I'm sure.

  5. Stray closed this discussion on 16 Feb, 2011 09:04 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