Dynamic view in Mediator

Kate's Avatar


04 Dec, 2013 09:47 PM


I used RB1 in my projects in the following way. I had external loaded gfx with linkage names. So I did something like this :

injector.mapClass(MyView, MyView);
var ClassReference : Class = getDefinitionByName(id) as Class;
mediatorMap.mapView(ClassReference, MyMediator);
in mediator I used getViewComponent and passed it into the MyView class.
MyView was injected to the mediator.

Now in RB2 I have no possibility to take view by getViewComponent .
Also I cannot inject view into Mediator, since I get its class only in runtime by getDefinitionByName.

Could you please give me sive piece of advice on how to handle this?

Thank you!

  1. Support Staff 1 Posted by Ondina D.F. on 05 Dec, 2013 01:46 PM

    Ondina D.F.'s Avatar

    Hello Kate,

    There might be an easier way to achieve the same with robotlegs 2. But, I don't quite understand your use case.

    What are your gfxs and what are they supposed to do in your app? Are they some assets / graphics that you are loading from a library? Are you using them for skinning? Do they get added to the stage?
    Do you want to mediate each of them or just the View that needs them?

    You inject MyView into MyMediator, but you actually want to mediate a gfx?

    Maybe using an interface for the dynamic views would solve your problem. Or maybe you're after a view factory ? Or maybe you just need a way to inject objects into a view, and in this case you could use the viewProcessorMap extension.

    Sorry for not being able to help you without knowing more about your use case.
    I've notified Shaun and creynders, so, maybe they will understand your question right away and give you advice:)


  2. 2 Posted by Kate on 05 Dec, 2013 01:55 PM

    Kate's Avatar

    Are they some assets / graphics that you are loading from a library? - yes
    Are you using them for skinning? - yes
    Do they get added to the stage? - yes, at some point, when my application had initialized and loaded everything.
    You inject MyView into MyMediator, but you actually want to mediate a gfx? - correct and I want to have a view for this gfx.

  3. 3 Posted by matej on 05 Dec, 2013 03:35 PM

    matej's Avatar

    I think she used the mediator to pass the view reference to main MyView.
    but now, the view is injected inside mediator, i don’t know if you have getViewComponent.

    You could make every dynamic class implement IDynamic interface. and then you map just once IDynamic to IDynamicMediator


    there you will

    and in initialise or whatever

    I hope this solves your use case, but there are much more elegant ways of doing this :)

    I also wander why do you need a reference of each view in your MyView, because mediator is created once the view is added to stage, and that means that dynamic classes are already on stage once you try to pass them to MyView

  4. 4 Posted by Kate on 05 Dec, 2013 04:15 PM

    Kate's Avatar

    I'll try to explain my case in more details.
    I have several sets of following (MyMediator-MyView-loaded gfx for it with linkage id Gfx_ID) ,(MyMediator1-MyView1-loaded gfx for it with linkage id Gfx_ID1), (MyMediator2-MyView2-loaded gfx for it with linkage id Gfx_ID2).
    so I did following.

    injector.mapClass(MyView, MyView);
    injector.mapClass(MyView1, MyView1);
    injector.mapClass(MyView2, MyView2);
    var ClassReference : Class = getDefinitionByName(Gfx_ID) as Class;
    mediatorMap.mapView(ClassReference, MyMediator);
    var ClassReference1 : Class = getDefinitionByName(Gfx_ID1) as Class;
    mediatorMap.mapView(ClassReference1, MyMediator);
    var ClassReference2 : Class = getDefinitionByName(Gfx_ID2) as Class;
    mediatorMap.mapView(ClassReference2, MyMediator);
    In each Mediator I get getViewComponent(get Movieclip of loaded gfx)
    and pass it to the correspondence View. So no any main view. Then I work with loaded gfx in view classes and each Mediator works with it's view.
    Does this make sense now?
    Sorry for being unclear and thank you for your replies!
  5. Support Staff 5 Posted by Ondina D.F. on 06 Dec, 2013 09:19 AM

    Ondina D.F.'s Avatar

    I feel bad, really bad, for not getting it.
    I don't understand the relationship between MyView1 and Gfx_ID1, for example.
    Is MyView1 the parent of Gfx_ID1? Is MyView1 mediated? Where is the mapping for its mediator? How and when are you adding MyView1 and Gfx_ID1 to the stage?
    It seems to me that you're injecting the parent view (MyView1) of Gfx_ID1 into Gfx_ID1's mediator, which is not a good idea. If so, where are you adding Gfx_ID1 to the stage? As Matej said, the mediator of Gfx_ID1 gets created the moment Gfx_ID1 is added to the stage.

    In my example bellow, SomeView is the parent of SomeAsset. When SomeView is added to the stage, SomeMediator is created. In SomeMediator you inject someView and someAsset, and pass someAsset to someView to be added to the stage. But, I'm afraid, I'm missing your point completely :)

    var ClassReference:Class = getDefinitionByName("basicPackage.views.components.SomeAsset") as Class;
    //mapping SomeAsset in order to be injected into SomeMediator
    // mapping SomeAsset in order to be injected into SomeAssetMediator
    viewProcessorMap.map(ClassReference).toProcess(new MediatorCreator( SomeAssetMediator));
    mediatorMap.map(SomeView).toMediator( SomeMediator);


    public var someView:SomeView;
    public var someAsset:SomeAsset;

    somewhere in the mediator you pass someAsset to someView to be added to the stage

    You could as well inject someAsset directly into someView, but that's probably not what you want.

  6. Ondina D.F. closed this discussion on 22 Jan, 2014 03:20 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