Mediators in Flash CS5
Hello Guys! Im a bit new to RobotLegs but im realy enjoying it. Just a question though. I know that mediators will fire up on ADDED TO STAGE event. Is there a way to make it fire without using addChild or dispatching ADDED TO STAGE event of that view object? Let's say a view object already on the stage?
Comments are currently closed for this discussion. You can start a new one.
2 Posted by Michal Wroblewski on 13 Oct, 2011 06:14 PM
Just use an instance of mediatorMap and use createMediator method.
Do you have any problems with Flash CS5 as you only mentioned it in the title?
3 Posted by Stray on 13 Oct, 2011 06:22 PM
Hi Nico,
you can manually attach a mediator - just make the mapping as normal, and then do:
mediatorMap.createMediator(viewOnStage);
This will trigger the mediatorMap to do the same as would happen if the view had just landed on the stage.
hth,
Stray
4 Posted by Stray on 13 Oct, 2011 06:28 PM
Ah! Thanks Michal, you beat me to it :)
5 Posted by Nico on 13 Oct, 2011 06:35 PM
Thanks so much guys! yeah, I've read it on the docs. One last question guys, where will i place the createMediator method? From the looks of it, i think i can only have access to the view inside the ViewMediator since my view is injected from there. Really sorry guys for such a noob question >.<
6 Posted by Nico on 13 Oct, 2011 06:37 PM
will it also trigger the onRegister event when creating the mediator manually instead of automatically?
7 Posted by Stray on 13 Oct, 2011 06:43 PM
Yes, it will also trigger that.
Where you call it depends entirely on your app - basically you simply need to make sure you've got access to both the mediatorMap and the view you want to mediate in the same place.
That could be in the context - as the view is a child of the contextView, if you can get to it through the contextView (but you'll obviously need to also keep a strong-typed reference to it to allow that - at least to it typed as MovieClip so that you can make use of the dynamic nature of MCs as simply targeting your nested view on an instance of DisplayObjectContainer should error).
Let me know if that's not clear,
Stray
8 Posted by Nico on 13 Oct, 2011 06:54 PM
Thanks so much stray! Ok, so yeah, I think inside the context would be the best way to go :D but yeah, i just noticed that i dont have any reference to the view object inside the context. any tips advice?
I have a reference of the context inside my Document class.
Thank you for your assistance guys :)
9 Posted by Stray on 13 Oct, 2011 07:02 PM
You pass your contextView to the context - yes?
So - if that's your root of your FLA, just keep that reference (typed as a MovieClip).
You should be able to reach the view object through that.
Stray
10 Posted by Nico on 13 Oct, 2011 07:14 PM
Nice! I think i got it now. I manually created the mediator for my view inside my context. then i created a reference to my view on the stage by means of contextView.getChildByName("viewObject").
It triggered the onRegister. Question is, is what im doing correct even if it does work?
ie: Inside my context
var myViewObject:MovieClip = contextView.getChildByName("viewObject") as MovieClip;
mediatorMap.createMediator(myViewObject);
11 Posted by Stray on 13 Oct, 2011 07:23 PM
Hi Nico,
that looks fine to me - but if you're declaring stage instances automatically (a setting in your swf) then you can just path to it directly.
What I was thinking was that when you passed in your contextView you would do:
_flaMovieClip = contextView;
then you can just do
var myViewObject:MovielClip = _flaMovieClip.viewObject;
.... and so on.
But what you're doing looks fine.
Stray
12 Posted by Nico on 13 Oct, 2011 08:41 PM
COOL! Thank you so much guys! you've been a great help!!!
Ondina D.F. closed this discussion on 01 Nov, 2011 03:34 PM.