Mediators in Flash CS5

Nico's Avatar


13 Oct, 2011 06:01 PM

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?

  1. 1 Posted by Michal Wroblews... on 13 Oct, 2011 06:14 PM

    Michal Wroblewski's Avatar

    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?

  2. 2 Posted by Stray on 13 Oct, 2011 06:22 PM

    Stray's Avatar

    Hi Nico,

    you can manually attach a mediator - just make the mapping as normal, and then do:


    This will trigger the mediatorMap to do the same as would happen if the view had just landed on the stage.



  3. 3 Posted by Stray on 13 Oct, 2011 06:28 PM

    Stray's Avatar

    Ah! Thanks Michal, you beat me to it :)

  4. 4 Posted by Nico on 13 Oct, 2011 06:35 PM

    Nico's Avatar

    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 >.<

  5. 5 Posted by Nico on 13 Oct, 2011 06:37 PM

    Nico's Avatar

    will it also trigger the onRegister event when creating the mediator manually instead of automatically?

  6. 6 Posted by Stray on 13 Oct, 2011 06:43 PM

    Stray's Avatar

    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,


  7. 7 Posted by Nico on 13 Oct, 2011 06:54 PM

    Nico's Avatar

    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 :)

  8. 8 Posted by Stray on 13 Oct, 2011 07:02 PM

    Stray's Avatar

    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.


  9. 9 Posted by Nico on 13 Oct, 2011 07:14 PM

    Nico's Avatar

    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;


  10. 10 Posted by Stray on 13 Oct, 2011 07:23 PM

    Stray's Avatar

    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.


  11. 11 Posted by Nico on 13 Oct, 2011 08:41 PM

    Nico's Avatar

    COOL! Thank you so much guys! you've been a great help!!!

  12. Ondina D.F. closed this discussion on 01 Nov, 2011 03:34 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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