tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/666-problem-with-medaitorRobotlegs: Discussion 2012-10-29T15:47:59Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/199806792012-10-24T09:00:47Z2012-10-24T09:00:47ZProblem with medaitor<div><p>Hello,</p>
<p>Take a look at this:<br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/wiki/Common-Problems#wiki-mediator-not-running-onregister">
https://github.com/robotlegs/robotlegs-framework/wiki/Common-Proble...</a></p>
<p>Please let us know whether it solved your problem or not.</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/199806792012-10-24T09:02:48Z2012-10-24T09:02:48ZProblem with medaitor<div><p>and this:<br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/wiki/Common-Problems#wiki-mysteriously-stops">
https://github.com/robotlegs/robotlegs-framework/wiki/Common-Proble...</a></p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/199806792012-10-24T09:46:21Z2012-10-24T09:46:21ZProblem with medaitor<div><p>Is it a Flex or a pure as3 project?</p>
<p>Could you post some code (or attach a simplified example)
showing:</p>
<p>-Context initialization in your main display object</p>
<p>-Order of the mappings in your Context</p>
<p>-Where and how you’re adding the view to the display
list</p>
<p>-What kind of a component is “Shop”. Is it by any
chance a popup container?</p>
<p>I think you’re adding the view to the display list before
the mapping was made.</p>
<p>In the case of Mediators the mappings have to occur before their
Views hit the stage.<br>
The moment a View is added to the display list the MediatorMap
creates a Mediator for that View, but only if they were already
mapped.<br>
Exception from the rule: the main application container.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/199806792012-10-24T20:52:27Z2012-10-24T20:52:27ZProblem with medaitor<div><p>Thanks for replay but any sugestion don't help me. Below pasted
a piece of my code.</p>
<p>Context initialization:</p>
<pre>
<code>override public function startup():void
{
....
mediatorMap.mapView(Shop, ShopMediator);
...
mediatorMap.mapView(GameFace, GameFaceMediator);
...
}</code>
</pre>
<p>Object of shop is create in GameFace:</p>
<pre>
<code>public function initShop(aX:Array):void
{
shop = new Shop();
_aX = aX;
}</code>
</pre>
<p>And was added to scene when player open shop in game:</p>
<pre>
<code> public function openShop(tab:uint = 100):void
{
shop = new Shop();
addChild(shop);
shop.init(_aX);
shop.x = 396;
shop.y = 267;
}</code>
</pre>
<p>Of course object of GameFace was added to display list.<br>
Someone know whats wrong is in my code?</p></div>patpas20tag:robotlegs.tenderapp.com,2009-10-18:Comment/199806792012-10-25T09:58:48Z2012-10-25T10:26:29ZProblem with medaitor<div><p>Hello,</p>
<p>You didn’t answer my questions, and you didn’t post
the code for context initialization in your main class. I
can’t see what’s going on from the snippet you posted.
I don’t know <strong>when</strong> is the view added and
<strong>where</strong>. Is GameFace your main class? Also, I
don’t know why you’re adding the view twice. [Edit]
<strong>created</strong> the view twice</p>
<p>I guess it’s a pure as3 project. I’ll attach a
simple project to show you how you should proceed, and hopefully
that will help you :)</p>
<p>Here, just the code for the ContextView.as</p>
<pre>
<code>public class ContextView extends Sprite
{
private var context:ApplicationContext;
public function ContextView()
{
trace("ContextView.ContextView()");
stage.align = StageAlign.TOP;
stage.scaleMode = StageScaleMode.NO_SCALE;
context = new ApplicationContext(this);
/////////////////////////////////////// [[[option 1]]]
createChildren();
addEventListener(Event.ADDED_TO_STAGE, onViewAdded);
}
private function onViewAdded(event:Event):void
{
trace("ContextView.onViewAdded(event)");
removeEventListener(Event.ADDED_TO_STAGE, onViewAdded);
/////////////////////////////////////// [[[option 2]]]
/*context = new ApplicationContext(this);
createChildren();*/
}
public function createChildren():void
{
trace("ContextView.createChildren()");
var someView:SomeView = new SomeView();
someView.x = 10;
someView.y = 20;
addChild(someView);
}
}</code>
</pre>
<p>1.Bad:<br>
createChildren();<br>
context = new ApplicationContext(this);</p>
<p>Here, SomeView is added to the stage <strong>before</strong> the
mappings in the context occurred, therefore its Mediator
(SomeMediator) can’t be created</p>
<p>2.Good:<br>
context = new ApplicationContext(this);//<strong>first create the
context</strong><br>
createChildren(); //<strong>then add the view</strong></p>
<p>Inside the code that I’ve attached to this post there are
4 places where you can add SomeView, and I commented them like
this:</p>
<p>[[[option 1]]] ContextView constructor</p>
<p>[[[option 2]]] ContextView on added to stage</p>
<p>[[[option 3]]] ApplicationContext on
ContextEvent.STARTUP_COMPLETE</p>
<p>[[[option 4]]] ApplicationMediator onRegister()</p>
<p>I used option 3: ApplicationContext. onStartUpComplete()</p>
<p>It is important that SomeView gets added to the stage after
mapping it to its mediator!!</p>
<p>If that doesn’t help you either, you’ll have to
attach an example reproducing the issues you’re having, and
I’ll take a look at it.</p>
<p>Ondina</p></div>Ondina D.F.