Removing and then adding a new Robotlegs 2 contextView to a Starling view

Marc's Avatar


18 Nov, 2013 11:50 AM


I'm working with an application where I have an existing Starling context and am using a fairly standard setup for it. (The rootclass is an empty Starling Sprite.) Starling is setup and initialized before Robotlegs is used in the application.

public static function init(rootClass : Class, stage : Stage, viewPort : Rectangle) : void
    if (!_isHandlingStarling)
        Starling.handleLostContext = true;
        starling = new Starling(rootClass, stage, viewPort);
        _starling.addEventListener(Event.CONTEXT3D_CREATE, onContextCreated);
        _starling.addEventListener(Event.ROOTCREATED, onRootCreated);
        _isHandlingStarling = true;

Once I have Starling initialized, I setup RobotLegs and add the view to Starling. So far, so good. I am also using the StarlingViewMapExtension and call CONTEXT.configure(Starling.current) while setting up the Robotlegs context.

protected override function init() : void
    starlingMainView = new StarlingMainView();
    Sprite(Starling.current.root).addChildAt(starlingMainView, 0);
    addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);

Now, this is where things break down. I want to remove the view from the Starling sprite, and shutdown Robotlegs. This appears to work and can see that the old Robotlegs context is destroyed.

private function onRemovedFromStage (event : Event) : void
    removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);

I then call init() again. A new Robotlegs context gets created, but then is not apparently used as injected objects are not available, when they worked fine during the first time around.

Essentially, I need to be able to have a single Starling context setup, and to be able to add an remove Robotlegs back 'applications' to that Starling instance. Any help is appreciated.


  1. Support Staff 1 Posted by Ondina D.F. on 18 Nov, 2013 06:12 PM

    Ondina D.F.'s Avatar

    Hey Marc,

    I can't follow your explanation. But, that's probably because I'm no expert in Starling. Occasionally, I get to debug someone else's app, when they post their issues with an rl Starling extension on this forum..

    I can't understand the hierarchy of your views. Which view is used by Starling, and which one is meant to be robotlegs' contextView? The code for the context creation is missing from your post.
    I'm sure I'm wrong, but it seems like you are trying to remove the main context instead of a sub-context?

    I hope someone with more Starling experience will help you with this. If you don't get an answer, you can attach a bare-bone project reproducing the issue, and I'll take a look at it tomorrow. Usually, I find the culprits pretty fast ;)


  2. 2 Posted by matej on 19 Nov, 2013 07:13 AM

    matej's Avatar

    Same here,

    can you explain a little bit more into detail what are you trying to achieve?

  3. Ondina D.F. closed this discussion on 23 Dec, 2013 09:26 AM.

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