tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/19-mapping-views-to-mediators-at-runtimeRobotlegs: Discussion 2018-10-18T16:35:06Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/6928442009-12-11T14:52:14Z2009-12-11T14:52:14Zmapping views to mediators at runtime<div><p>Hi Tim,</p>
<p>Sorry for the delay. The reason it's not working is that the
first argument to mediatorMap.mapView() needs to be a class (not an
instance). And that class needs to be the concrete class of the
instance that lands on stage - ie, screen_tips (which is a class,
yes?) not ScreenObject (ie, not an abstract class or
interface).</p>
<p>The MediatorMap watches for instances of the view classes you
have mapped to arrive on stage. When such an instance arrives, it
creates a mediator for it and passes a reference of the view
instance to that mediator. For example:</p>
<p>mediatorMap.mapView( MyComponentClass, MyMediator );</p>
<p>When an instance of MyComponentClass lands on stage, a new
MyMediator instance will be created. If MyMediator wants a
reference to the view that created it, you do this in the Mediator
class:</p>
<p>[Inject] public var component:MyComponentClass;</p>
<p>Unfortunately, for performance reasons, you have to map by
concrete types.</p>
<p>Does that help to clear things up a little? Or have I missed the
point of what you are wanting to do?</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/6928442009-12-14T10:30:37Z2009-12-14T10:30:38Zmapping views to mediators at runtime<div><p>Thanks for your reply. I've solved my problem by creating an
array with all the class which needed to be mapped to the
ScreenMediator, and did the same for the WindowMediator.</p>
<p>After loading the assets the classes are mapped to the right
mediators, then the movieclip containing the views (that are now
mapped) are added to the stage.</p></div>Tim vd Eijnden