• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

createJS - Uncaught ReferenceError: lib is not defined

Explorer ,
Oct 18, 2018 Oct 18, 2018

Copy link to clipboard

Copied

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

Views

3.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 19, 2018 Oct 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;

 

...

Votes

Translate

Translate
Adobe Employee ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

Thank you. I will post an answer if I get to that point. Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

Thanks, JC!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

JC,

Thank you so much for responding. I am new to Adobe Animate and am not quite sure what you mean by "assuming that this line is being called from some timeline in your FLA document  ".

How do I do that? Or can you point me to do documentation?

I did follow all your other suggestions and still get the error: Uncaught ReferenceError: lib is not defined. It is complaining about this line: var game = new Game(lib);

Thank you so much for your help!!!

Ramona

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

Hi.

Here is a sample:

animate_cc_html5_lib_not_defined.zip - Google Drive

Please notice that in the NumberedBox class I'm using the setTimeout method to make sure that the children is ready to be targeted. This is how things work in ANCC for some reason.

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

JC,

Thanks so much!!! Your answer is the correct one!!! I just called var game = new Game(lib); from a actions tab associated with the first keyFrame and everything seems to be working smoothly. I just learned a lot! I am still a little confused as to why I need to call this line from Adobe Animate but maybe that will become more clear as I learn (unless you want to clarify). Thanks again!!

Best,

Ramona

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

LATEST

Excellent!

You're welcome.

Have a great learning adventure and please don't hesitate to come by if you need some help.

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines