Implementing a SceneManager

Hello everyone!

I’m currently trying to implement a simple SceneManager. I’m new to OpenFL and Haxe so I don’t really know how to do it because my latest attempts failed. Here is one of my attempts:

package;

import openfl.display.Sprite;
import openfl.display.DisplayObject;
import openfl.Lib;

class SceneManager extends Sprite
{
    private var currentScene: DisplayObject;

    public function new(rootScene: DisplayObject)
    {
        super();

        currentScene = rootScene;
        Lib.current.addChild(currentScene);
    }

    public function changeScene(newScene: DisplayObject): Void
    {
         Lib.current.removeChild(currentScene);

        currentScene = newScene;
        Lib.current.addChild(currentScene);
    }
}

If anyone can help me I would be really grateful.

Thank you!

What exactly doesn’t work? Maybe try these instead?

Lib.current.stage.addChild

and

Lib.current.stage.removeChild

I finally made it work. The problem was that in the scene classes I added used “Lib.current.stage.addChild” instead of “this.addChild”.