About best practic to Inject DisplayObject through Interface

smival's Avatar


03 Dec, 2014 08:10 AM

I have a Mediator and some view object:

this.mediatorMap.mapView(MainView, MainViewMediator);

In the Mediator constructor my code adds all childs of this DisplayObject to the display list:

public var background:Image = new Image(...);
public var counter:Counter = new Counter();
public var someObject:ISomeObject = new SomeObject();

public function MainView()
addChild(someObject as DisplayObject);

My goal is control the ISomeObject in Context file, something like that:

this.injector.mapSingletonOf(ISomeObject, SomeObject);

It will be easy to choose what exactly DisplayObject I need at the moment, may be:

this.injector.mapSingletonOf(ISomeObject, SomeAnotherObject);

So to implement this idea I'm gonna to remove all code about ISomeObject from MainView and put it to MainViewMediator:

public var someObject:ISomeObject;

public var vo:MainView;

override public function onRegister():void
vo.addChild(someObject as DisplayObject);

Did not try it, but it should be ok.
The question is: This approach looks not good and may be here is more best practic than I suggested?


  1. 1 Posted by smival on 03 Dec, 2014 08:22 AM

    smival's Avatar

    ps - Robotlegs 1
    pps - Of course here could be a lot of different Interfaces in this single MainViewMediator

  2. Support Staff 2 Posted by Ondina D.F. on 03 Dec, 2014 05:10 PM

    Ondina D.F.'s Avatar

    Hi Valentin,

    Perhaps a view factory could be a better solution for your problem. See this discussion:



  3. 3 Posted by smival on 11 Dec, 2014 09:29 AM

    smival's Avatar

    thanks a lot, I will learn it

  4. Support Staff 4 Posted by Ondina D.F. on 17 Dec, 2014 02:56 PM

    Ondina D.F.'s Avatar

    You're welcome!

  5. Ondina D.F. closed this discussion on 17 Dec, 2014 02:56 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