how to add a view multi times when the view maped to Mediator?
I have a view named ContactView
,and it have
Mediator named ContactMediator
,when I click the
contact button,it will be show.
I used
mediatorMap.map(ContactView).toMediator(ContactMediator);
in Config
and
addChild(new ContactView());
in the button
listener
but the ContactView will be create every time when I
addChild
, I need it just single,so I add these code in
Config
injector.map(ContactView).asSingleton();
and
[Inject] public var contact:ContactView;
when I add the view to stage use
addChild(contact);
, have a error
Warning: Injector already has a mapping for ContactView|.
If you have overridden this mapping intentionally you can use
"injector.unmap()" prior to your replacement mapping in order to
avoid seeing this message.
How can I got a view or mediator instance from somewhere?
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 10 Jun, 2013 11:30 AM
Hello yellow,
First of all, you can’t add the same instance of a display object to the stage twice. A display object can have only one parent at a time.
If you have something like this:
var someView:SomeView = new SomeView();
and try to do this:
someContainer.addElement(someView);
someContainer.addElement(someView);
the second call would fail:
If you’d add someView to someContainer and also to anotherContainer, the same instance of someView would be removed from someContainer and then added to anotherContainer – it would be re-parented. (Adobe: If you add a visual element that already has a different container as a parent, the element is removed from the other container.)
So, you can’t avoid creating new instances of your view.
What exactly do you want to achieve? Could you give us more details?
Concerning the error you’re getting, as it says, you have overridden the first mapping for ContactView with the second one:
injector.map(ContactView).asSingleton();
mediatorMap.map(ContactView).toMediator(ContactMediator);
For a workaround, see Shaun’s answer :
http://knowledge.robotlegs.org/discussions/robotlegs-2/698-mapping-...
Ondina
Support Staff 2 Posted by Ondina D.F. on 10 Jun, 2013 01:02 PM
JFYI
You’re not the only one wanting to have a Single DisplayObject in multiple containers ;)
See: http://www.bytearray.org/?p=751
3 Posted by yellow.as on 10 Jun, 2013 01:44 PM
hi, Ondina
thank you,
sorry, I may have a problem narrative.
I think
ContactView
is a Singleton.Click contact button to show
ContactView
, and there is a close button inContactView
, when click the close button,ContactView
will remove from stage.when I click the contact button second times, I want to show the
ContactView
just has removed, notnew ContactView
.so, I need a way to get the same
ContactView
instance in other MediatorSupport Staff 4 Posted by Ondina D.F. on 10 Jun, 2013 02:38 PM
If I understood correctly, you want something like this:
It creates just one instance of contactView. If you already added it to the stage, and you click the createContactButton, nothing will happen. If you removed it from stage, and you click createContactButton, the same instance of contactView will be added to the stage.
But, I don’t understand what you mean here:
You want to map it to another mediator, other than ContactMediator, or do you want to inject it into a mediator of another view? Could you explain what you need?
5 Posted by yellow.as on 10 Jun, 2013 02:51 PM
hi, Ondina,
OMG, I forgot that.
when I used robotlegs, I just got [Inject] [Inject] [Inject]....
I'm sorry to waste your time.
thank you very much!
Support Staff 6 Posted by Ondina D.F. on 10 Jun, 2013 02:58 PM
hehe, no problem; I'm glad you're back on track.
Ondina D.F. closed this discussion on 10 Jun, 2013 02:58 PM.