Search code examples
javascriptcreatejs

Is it possible to make a stage accessible in all scripts using CreateJS?


I want to add a Bitmap to the stage from a different script than the one it is created in. Is this possible? Currently it gives the error "stage is not defined".


Solution

  • If you put "stage" in the global scope you can access it from anywhere.

    File #1:

    var stage;
    function init()
    {
        stage = new createjs.Stage(canvas);
    }
    

    File #2

    stage.addChild(bitmap);
    

    You can (and should) read more about scope here