Guido La Rosa
Guido La Rosa

Reputation: 15

Error adding child to stage with EaselJS on createjs -- a.dispatchEvent is not a function

I'm using the createjs suite and JQuery.
When I try to add a child to the stage the console gives me the following error:

enter image description here

This is the code written:

function intro(stageProperties) {
  console.log('Playing Intro');
  console.log(stage);
  console.log($CANVAS_W);

  let background = new createjs.Graphics();
  background.beginFill('black');
  background.drawRect($CANVAS_W,$CANVAS_H);
  stage.addChild(background);

  runTicker();

  // Draw company plaque and game title
  setTimeout(function(){
    instructions();
  },1000 * 5)
};

I've been trying to make this run for a long time, but I don't know what I'm doing wrong.

I've seen that there could be a conflict between the createjs suite and JQuery, but I still can't figure it out.

Upvotes: 1

Views: 471

Answers (1)

Lanny
Lanny

Reputation: 11294

You can't add Graphics directly to the stage. Graphics define how to draw the contents of a Shape. They can be shared between Shape instances too.

You need to wrap your Graphics in a Shape instance, and add that to the stage instead:

var shape = new createjs.Shape(background);

Cheers.

Upvotes: 1

Related Questions