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

using the added event listerner

New Here ,
Feb 28, 2017 Feb 28, 2017

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?

270
Translate
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

LEGEND , Feb 28, 2017 Feb 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);
Translate
LEGEND ,
Feb 28, 2017 Feb 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);
Translate
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
New Here ,
Feb 28, 2017 Feb 28, 2017

ah! yes.

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

Translate
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
New Here ,
Feb 28, 2017 Feb 28, 2017
LATEST

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);
Translate
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