Map a MovieClip Instance to a Mediator
I got a problem
I thought I could do something like this
this.mediatorMap.registerMediator( myViewComp.mc1, new MC1Mediator());
this.mediatorMap.registerMediator( myViewComp.mc2, new MC2Mediator());
but there must be something wrong, I can't get viewComp in those Mediators
I am wondering why I can't get the viewComp I expected in my Mediators
Is there any possible to doing that
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Ondina D.F. on 04 Sep, 2013 12:28 PM
Hello,
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?
Anyway, if you look at registerMediator() [https://github.com/robotlegs/robotlegs-framework/blob/v1.0.3/src/or...]
you can see that it expects a view as an Object ( not Class) and a mediator as IMediator.
Instead of this mapping
mediatorMap.registerMediator(SomeView, new SomeMediator());
you'd need this:
var view:SomeView = new SomeView();
var mediator:* = injector.instantiate(SomeMediator);
mediatorMap.registerMediator(view, mediator);
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)
So, we add a mapping for SomeView:
var view:SomeView = new SomeView();
injector.mapValue(SomeView, view);
var mediator:* = injector.instantiate(SomeMediator);
mediatorMap.registerMediator(view, mediator);
and then we add the view to the stage:
someContainer.addElement(view);
But that's exactly what createMediator() does.
So, instead of the above you could do this:
Map the view to the mediator in you config.
mediatorMap.mapView(SomeView, SomeMediator);
Create a new SomeView and a new SomeMediator
var view:SomeView = new SomeView();
mediatorMap.createMediator(view);
[EDIT]
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 :
mediatorMap .mapView(viewClassOrName:*, mediatorClass:Class, injectViewAs:*=null, autoCreate:Boolean=true, autoRemove:Boolean=true):void
Add the view to the stage:
someContainer.addElement(view);
Let me know if that helps.
Ondina
Ondina D.F. closed this discussion on 23 Sep, 2013 02:38 PM.