tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/26-failing-to-map-mediatorRobotlegs: Discussion 2018-10-18T16:35:07Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/8110312010-01-06T16:47:55Z2010-01-06T16:47:55ZFailing to Map Mediator<div><p>Hey Craig,</p>
<p>the piece of code you stepped to is just a special case handling
that<br>
enables seamless mediation of the context view itself. I guess
your<br>
ViewA isn't the context view but some view inside that,
correct?<br>
If so, then you can ignore this part - the if statement should fail
as it does.</p>
<p>As for the error you get:<br>
Robotlegs works by automatically creating instances of the
mediator<br>
class you mapped for your view class as soon as an instance of
the<br>
latter gets added to the display list anywhere below your
context<br>
view.<br>
It looks like you're trying to not only create the mediator but
also<br>
the view itself with the line<br>
mediatorMap.createMediator(ViewA)<br>
The error you get is caused by Robotlegs trying to inject what
you<br>
supplied to createMediator - the <em>class</em> ViewA - into a
variable on<br>
your mediator that expects something different - namely <em>an
instance</em><br>
of the class ViewA.</p>
<p>Instead, you can (after creating the mapping as you now do
in<br>
MyContext#startup) add an instance of ViewA to the context view
(or<br>
one of its children) and the mediator gets created
automatically.</p>
<p>The smallest change to your code that should create working
results would be:<br>
override public function startup():void {</p>
<pre>
<code> mediatorMap.mapView(ViewA, ViewAMediator);
contextView.addChild(new ViewA());</code>
</pre>
<p>}</p>
<p>Note that you wouldn't normally create view instances in
your<br>
Context#startup method - this is just to demonstrate that views
get<br>
mediated automatically after being added to the stage.</p>
<p>cheers,<br>
till</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/8110312010-01-06T16:53:42Z2010-02-28T00:44:31ZFailing to Map Mediator<div><p>Nevermind, apparently I was trying to create my context after
ADDED_TO_STAGE<br>
occurred, I thought it was in the onPreInitialize but it wasn't,
now it is.</p>
<p>@till -- thanks for the heads up / info so quickly</p></div>codecraig