tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/3743-map-a-movieclip-instance-to-a-mediatorRobotlegs: Discussion 2014-04-24T08:26:19Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/286178752013-09-04T12:28:10Z2014-04-24T08:26:19ZMap a MovieClip Instance to a Mediator<div><p>Hello,</p>
<p>I'm not sure if you really wanted to use mediatorMap
.registerMediator(), or if you mistook it for
mediatorMap.mapView(). Could you give us more info about your use
case? Why do you need to use registerMediator, i.e. what do you
want to achieve exactly?</p>
<p>Anyway, if you look at registerMediator() [<a href=
"https://github.com/robotlegs/robotlegs-framework/blob/v1.0.3/src/org/robotlegs/base/MediatorMap.as#L159">https://github.com/robotlegs/robotlegs-framework/blob/v1.0.3/src/or...</a>]<br>
you can see that it expects a view as an Object ( not Class) and a
mediator as IMediator.</p>
<p>Instead of this mapping<br>
<code>mediatorMap.registerMediator(SomeView, new
SomeMediator());</code></p>
<p>you'd need this:</p>
<p><code>var view:SomeView = new SomeView();<br>
var mediator:* = injector.instantiate(SomeMediator);<br>
mediatorMap.registerMediator(view, mediator);</code></p>
<p>But the view won't be injected into the mediator because the
Injector will be missing a rule to handle the injection into target
(mediator)</p>
<p>So, we add a mapping for SomeView:</p>
<p><code>var view:SomeView = new SomeView();<br>
injector.mapValue(SomeView, view);<br>
var mediator:* = injector.instantiate(SomeMediator);<br>
mediatorMap.registerMediator(view, mediator);</code></p>
<p>and then we add the view to the stage:<br>
someContainer.addElement(view);</p>
<p>But that's exactly what createMediator() does.<br>
So, instead of the above you could do this:</p>
<p>Map the view to the mediator in you config.</p>
<p><code>mediatorMap.mapView(SomeView, SomeMediator);</code></p>
<p>Create a new SomeView and a new SomeMediator</p>
<p><code>var view:SomeView = new SomeView();<br>
mediatorMap.createMediator(view);</code></p>
<p>[EDIT]</p>
<p>Usually, that's only needed for mediating components like
Popups. Regular views are mediated automatically, when they are
added to the contextView's stage, provided you mapped them to a
mediator, and autoCreate is set to true :<br>
mediatorMap .mapView(viewClassOrName:*, mediatorClass:Class,
injectViewAs:*=null, autoCreate:Boolean=true,
autoRemove:Boolean=true):void</p>
<p>Add the view to the stage:<br>
someContainer.addElement(view);</p>
<p>Let me know if that helps.<br>
Ondina</p></div>Ondina D.F.