ContextView in RL2 with Starling

khaneron_898's Avatar

khaneron_898

21 Jul, 2013 03:09 PM

Hi I want to ask if we use Starling in RL2 by using StarlingViewMapExtension
like from this example
https://github.com/lidev/robotlegs2-signals-feathers-flickr-example/
and in this cace FlickrGalleryApp.as class (FlickGalleryApp.as is extends flash.display.Sprite)

 _context = new Context();
_context.install( MVCSBundle, StarlingViewMapExtension, SignalCommandMapBundle );
_context.configure( AppConfig, this, _starling );
_context.configure( new ContextView( this ) );

if I

[Inject]
public var contextView:ContextView;

to some command , will contextView.view automatically return as starling.display.DisplayObjectContainer . ?

or I should change it to


_context.configure( new ContextView( _starling.stage) );
or
_context.configure( new ContextView(Starling.current.root) );

so I can add display object like

 contextView.view.addChild(new SomeStarlingDisplayObject());
or is there other example/best practice using RL2 with feathers/starling ? I only found two so far
Thanks for the advice
  1. Support Staff 1 Posted by Ondina D.F. on 22 Jul, 2013 01:41 PM

    Ondina D.F.'s Avatar

    Hi,

    Adding "this" to the configure doesn't make sense:
    _context.configure( AppConfig, this, _starling );

    This is the correct configuration:

    _context.configure(AppConfig, _starling , new ContextView( this ));

    if I [Inject] public var contextView:ContextView;
    to some command , will contextView.view automatically return as
    starling.display.DisplayObjectContainer . ?

    As you know, the ContextView is expecting a DisplayObjectContainer, and every time you call contextView.view, it will return the display object container that you provided, in your example that's FlickGalleryApp, which is not a starling.display.DisplayObjectContainer.

    _context.configure( new ContextView( _starling.stage) ); or
    _context.configure( new ContextView(Starling.current.root) );

    That's not a good idea, and I think it wouldn't work actually. I'm not very familiar with Starling, but just from looking at the class, I guess Starling adds a view as a Starling root Class to an already created stage. So you need to pass on to it a parent view (FlickGalleryApp) and a view (StarlingRootSprite) to be added to its parent's stage (FlickGalleryApp.stage).
    FlickGalleryApp is the DisplayObjectContainer used by robotlegs' ContextView, while StarlingRootSprite is the 'root class' used by Starling. That means, you'll never get StarlingRootSprite by calling contextView.view.

    It would be better if you could avoid manipulating views in a command (adding views is View logic !), but if you really need to do that, you can access starling's instance like so :

    (contextView.view as Object)._starling.stage.addChild(views);

    which is pretty disturbing ;)

    or you can inject an instance of Starling that you mapped like so:

    _starling=new Starling(StarlingRootSprite, stage, null, null, "auto", "baseline");
    _context.injector.map(Starling, "starlingInstance").toValue(_starling);
    

    and then inject it like this:

    [Inject(name="starlingInstance")]      
    public var starling:Starling;
    
    starling.stage.addChild(view);
    

    SARS is a nice utility. In SARS, the mapping of a Starling instance happens behind the scenes, and all you have to do is inject the instance into the command.
    (https://github.com/Vj3k0/robotlegs-bender-example-SARS-integration/...)

    Hope this helps.
    Ondina

  2. 2 Posted by khaneron_898 on 22 Jul, 2013 02:11 PM

    khaneron_898's Avatar

    Thanks for the reply , much more clear now

  3. Support Staff 3 Posted by Ondina D.F. on 22 Jul, 2013 03:30 PM

    Ondina D.F.'s Avatar

    Glad to hear that!

  4. Ondina D.F. closed this discussion on 22 Jul, 2013 03:30 PM.

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