Skip to main content
Known Participant
February 28, 2017
Answered

using the added event listerner

  • February 28, 2017
  • 3 replies
  • 304 views

working in a canvas project. when i use the following code, the pic loads fine, but i don't get the trace alert.

var page1Pic = new createjs.Bitmap("page1.0.png")

root.addChild(page1Pic);

page1Pic.addEventListener("added", picAdded);

function picAdded(event){

  alert("Trace");

  // my goal here would be to start loading a second picture

};

if i use the "click" event listener, as in the following code, i get the trace alert.

var page1Pic = new createjs.Bitmap("page1.0.png")

root.addChild(page1Pic);

page1Pic.addEventListener("click", picAdded);

function picAdded(event){

  alert("Trace");

};

what gives?

is there a better way to load one pic and display it before starting to load the next pic?

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer Colin Holgate

Try adding the listening before you add the bitmap. Otherwise it's too late.

  1. var page1Pic = new createjs.Bitmap("page1.0.png"
  2. page1Pic.addEventListener("added", picAdded);
  3. root.addChild(page1Pic);

3 replies

Numinus67Author
Known Participant
March 1, 2017

what's a simple way to make the added child the same width as the container into which it is added?

i.e. if i add the bitmap to a movie clip on the stage like so:

  1. var page1Pic = new createjs.Bitmap("page1.0.png"
  2. root.picTarget.addChild(page1Pic);
Numinus67Author
Known Participant
March 1, 2017

ah! yes.

colin, i'm an idiot, and you're my favorite person in the world.

Colin Holgate
Colin HolgateCorrect answer
Inspiring
February 28, 2017

Try adding the listening before you add the bitmap. Otherwise it's too late.

  1. var page1Pic = new createjs.Bitmap("page1.0.png"
  2. page1Pic.addEventListener("added", picAdded);
  3. root.addChild(page1Pic);