tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/80-mediators-do-not-map-when-view-is-on-multiple-stages-in-airRobotlegs: Discussion 2013-04-28T10:02:17Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/14479512010-04-14T06:31:33Z2010-04-14T06:31:33ZMediators do not map when View is on multiple stages in AIR<div><p>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 <em>should</em> exist. It just doesn't yet.</p>
<p>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:</p>
<ul>
<li>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.</li>
<li>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.</li>
</ul>
<p>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.</p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/14479512010-04-14T06:43:57Z2010-04-14T06:43:57ZMediators do not map when View is on multiple stages in AIR<div><p>Let me be more specific.</p>
<p>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.</p>
<p>public Window class extends Sprite<br>
{</p>
<pre>
<code>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);
_nativeWindow.stage.addChild(this);
}</code>
</pre>
<p>}</p></div>stevensackstag:robotlegs.tenderapp.com,2009-10-18:Comment/14479512010-04-14T07:17:46Z2010-04-14T07:17:46ZMediators do not map when View is on multiple stages in AIR<div><p>You can wait forever and the mediatorMap is not going to
automatically mediate the views within your additional Windows (as
it currently exists).</p>
<p>mediatorMap.createMediator(yourViewYouAreAddingToWindows);</p>
<p>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 ;)<br></p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/14479512010-04-16T15:17:24Z2010-04-16T15:17:24ZMediators do not map when View is on multiple stages in AIR<div><p>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
<code>mediatorMap.createMediator(view)</code>. It's sucky, we know.
We'll address this with RL v2 I'm sure.</p></div>Shaun Smith