Skip to main content
ramonas95472076
Known Participant
October 18, 2018
Answered

createJS - Uncaught ReferenceError: lib is not defined

  • October 18, 2018
  • 2 replies
  • 4566 views

I am at the beginning stages of creating a game using I am using Adobe Animate CC and CreateJS and I get the following error: Uncaught ReferenceError: lib is not defined. Basically right now I am just trying to get a background and some random numbers to appear on screen. I have created my background and random numbers as symbols in Adobe Animate, and I have also given them a class name by assigning them "linkage". I have included the javascript file created by Animate in my html along with a link to CreateJS and the following code:

Here is my Javascript code:

class NumberedBox extends createjs.Container
{
 
constructor(number=0)
 
{
  
super();
  
var movieclip = new lib.NumberedBox();
  movieclip
.numberedText.text = number;
  
this.addChild(movieclip);

  movieclip
.x = Math.random() * 200;
  movieclip
.y = Math.random() * 200;
 
}

}



class Game {

constructor()
{
  
this.canvas = document.getElementById("canvas");
  
this.stage = new createjs.Stage(this.canvas);

  createjs
.Ticker.framerate = 60;
  createjs
.Ticker.on("tick", this.stage);

  
this.stage.addChild(new lib.Background());
  
this.stage.addChild(new NumberedBox(88));
}

}

var game = new Game();

And here is my HTML:

<script src="https://code.createjs.com/createjs-2015.11.26.min.js"></script>

<script src="scripts/count-game-graphics.js"></script>

<script src="scripts/es6-games_ori.js"></script>

Any ideas as to what I am doing wrong?

Thanks

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

Unlike the canvas and stage properties, the lib property is not accessible from all places. You'll have to send it as a parameter when you instantiate your Game class. Like this:

class NumberedBox extends createjs.Container

{

    constructor(lib, number = 0)

    {

          super();

          var movieclip = new lib.NumberedBox();

          movieclip.numberedText.text = number;

          this.addChild(movieclip);

          movieclip.x = Math.random() * 200;

          movieclip.y = Math.random() * 200;

    }

}

class Game

{

    constructor(lib)

    {

          this.lib = lib;

          this.canvas = document.getElementById("canvas"); // you can call the canvas property from anywhere without doing this
         
this.stage = new createjs.Stage(this.canvas); // a stage is already created for you

          createjs.Ticker.framerate = 60;

          createjs.Ticker.on("tick", this.stage);

          this.stage.addChild(new lib.Background());

          this.stage.addChild(new NumberedBox(lib, 88));

    }

}

var game = new Game(lib); // assuming that this line is being called from some timeline in your FLA document

Regards,

JC

2 replies

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
October 19, 2018

Hi.

Unlike the canvas and stage properties, the lib property is not accessible from all places. You'll have to send it as a parameter when you instantiate your Game class. Like this:

class NumberedBox extends createjs.Container

{

    constructor(lib, number = 0)

    {

          super();

          var movieclip = new lib.NumberedBox();

          movieclip.numberedText.text = number;

          this.addChild(movieclip);

          movieclip.x = Math.random() * 200;

          movieclip.y = Math.random() * 200;

    }

}

class Game

{

    constructor(lib)

    {

          this.lib = lib;

          this.canvas = document.getElementById("canvas"); // you can call the canvas property from anywhere without doing this
         
this.stage = new createjs.Stage(this.canvas); // a stage is already created for you

          createjs.Ticker.framerate = 60;

          createjs.Ticker.on("tick", this.stage);

          this.stage.addChild(new lib.Background());

          this.stage.addChild(new NumberedBox(lib, 88));

    }

}

var game = new Game(lib); // assuming that this line is being called from some timeline in your FLA document

Regards,

JC

Preran
Legend
October 19, 2018

Thanks, JC!

Preran
Legend
October 19, 2018

I am guessing that it is you that posted this question on Stack Overflow: javascript - createJS - Uncaught ReferenceError: lib is not defined - Stack Overflow

If you don't receive help here, but get an answer on the other site, can you post the solution that worked for you here for the benefit of other users?

Thanks,

Preran

ramonas95472076
Known Participant
October 19, 2018

Hi Prean,

Are you staff at Adobe? So you don't have the answer? Are you having the same issue? Any help would gladly be appreciated.

Thanks for your reply,

Ramona

Preran
Legend
October 19, 2018

I am an Adobe employee in charge of the running of this forum, but am not an expert. I try to do my best to help in the time that the other experts pitch in. I encourage you to stay tuned to suggestions here.