tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/8523-dynamic-view-in-mediatorRobotlegs: Discussion 2014-01-22T15:20:34Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/303712292013-12-05T13:46:03Z2013-12-05T13:46:03ZDynamic view in Mediator<div><p>Hello Kate,</p>
<p>There might be an easier way to achieve the same with robotlegs
2. But, I don't quite understand your use case.</p>
<p>What are your gfxs and what are they supposed to do in your app?
Are they some assets / graphics that you are loading from a
library? Are you using them for skinning? Do they get added to the
stage?<br>
Do you want to mediate each of them or just the View that needs
them?</p>
<p>You inject MyView into MyMediator, but you actually want to
mediate a gfx?</p>
<p>Maybe using an interface for the dynamic views would solve your
problem. Or maybe you're after a view factory ? Or maybe you just
need a way to inject objects into a view, and in this case you
could use the viewProcessorMap extension.</p>
<p>Sorry for not being able to help you without knowing more about
your use case.<br>
I've notified Shaun and creynders, so, maybe they will understand
your question right away and give you advice:)</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/303712292013-12-05T13:55:19Z2013-12-05T14:04:40ZDynamic view in Mediator<div><p>Are they some assets / graphics that you are loading from a
library? - yes<br>
Are you using them for skinning? - yes<br>
Do they get added to the stage? - yes, at some point, when my
application had initialized and loaded everything.<br>
You inject MyView into MyMediator, but you actually want to mediate
a gfx? - correct and I want to have a view for this gfx.</p></div>Katetag:robotlegs.tenderapp.com,2009-10-18:Comment/303712292013-12-05T15:35:08Z2013-12-05T15:35:08ZDynamic view in Mediator<div><p>I think she used the mediator to pass the view reference to main
MyView.<br>
but now, the view is injected inside mediator, i don’t know
if you have getViewComponent.</p>
<p>You could make every dynamic class implement IDynamic interface.
and then you map just once IDynamic to IDynamicMediator</p>
<p>mediator.map(IDynamic).to(IDynamicMediator);</p>
<p>there you will<br>
[Inject] view:IDynamic;<br>
[Inject] myView:MyView;</p>
<p>and in initialise or whatever<br>
myView.passView(view);</p>
<p>I hope this solves your use case, but there are much more
elegant ways of doing this :)</p>
<p>I also wander why do you need a reference of each view in your
MyView, because mediator is created once the view is added to
stage, and that means that dynamic classes are already on stage
once you try to pass them to MyView</p></div>matejtag:robotlegs.tenderapp.com,2009-10-18:Comment/303712292013-12-05T16:15:01Z2013-12-05T16:15:04ZDynamic view in Mediator<div><p>I'll try to explain my case in more details.<br>
I have several sets of following (MyMediator-MyView-loaded gfx for
it with linkage id Gfx_ID) ,(MyMediator1-MyView1-loaded gfx for it
with linkage id Gfx_ID1), (MyMediator2-MyView2-loaded gfx for it
with linkage id Gfx_ID2).<br>
so I did following.<br></p>
<pre>
<code>injector.mapClass(MyView, MyView);
injector.mapClass(MyView1, MyView1);
injector.mapClass(MyView2, MyView2);
var ClassReference : Class = getDefinitionByName(Gfx_ID) as Class;
mediatorMap.mapView(ClassReference, MyMediator);
var ClassReference1 : Class = getDefinitionByName(Gfx_ID1) as Class;
mediatorMap.mapView(ClassReference1, MyMediator);
var ClassReference2 : Class = getDefinitionByName(Gfx_ID2) as Class;
mediatorMap.mapView(ClassReference2, MyMediator);</code>
</pre>
In each Mediator I get getViewComponent(get Movieclip of loaded
gfx)<br>
and pass it to the correspondence View. So no any main view. Then I
work with loaded gfx in view classes and each Mediator works with
it's view.<br>
Does this make sense now?<br>
Sorry for being unclear and thank you for your replies!</div>Katetag:robotlegs.tenderapp.com,2009-10-18:Comment/303712292013-12-06T09:19:35Z2013-12-06T09:19:35ZDynamic view in Mediator<div><p>I feel bad, really bad, for not getting it.<br>
I don't understand the relationship between MyView1 and Gfx_ID1,
for example.<br>
Is MyView1 the parent of Gfx_ID1? Is MyView1 mediated? Where is the
mapping for its mediator? How and when are you adding MyView1 and
Gfx_ID1 to the stage?<br>
It seems to me that you're injecting the parent view (MyView1) of
Gfx_ID1 into Gfx_ID1's mediator, which is not a good idea. If so,
where are you adding Gfx_ID1 to the stage? As Matej said, the
mediator of Gfx_ID1 gets created the moment Gfx_ID1 is added to the
stage.</p>
<p>In my example bellow, SomeView is the parent of SomeAsset. When
SomeView is added to the stage, SomeMediator is created. In
SomeMediator you inject someView and someAsset, and pass someAsset
to someView to be added to the stage. But, I'm afraid, I'm missing
your point completely :)</p>
<pre>
<code>var ClassReference:Class = getDefinitionByName("basicPackage.views.components.SomeAsset") as Class;
//mapping SomeAsset in order to be injected into SomeMediator
injector.map(ClassReference).asSingleton();
// mapping SomeAsset in order to be injected into SomeAssetMediator
viewProcessorMap.map(ClassReference).toProcess(new MediatorCreator( SomeAssetMediator));
mediatorMap.map(SomeView).toMediator( SomeMediator);</code>
</pre>
<p>SomeMediator</p>
<pre>
<code>[Inject]
public var someView:SomeView;
[Inject]
public var someAsset:SomeAsset;</code>
</pre>
<p>somewhere in the mediator you pass someAsset to someView to be
added to the stage</p>
<p>You could as well inject someAsset directly into someView, but
that's probably not what you want.</p></div>Ondina D.F.