EaselJS: Can't add event listener to an EaselJS + Box2dWeb example

1k Views Asked by At

I'm trying to add an event listener to the example here: http://www.luxanimals.com/blog/article/combining_easel_box2d

What I'm trying to do is, I changed the Bitmap to

var birdBMP = new createjs.Bitmap("images/bird.png");
            birdBMP.x = Math.round(Math.random()*500);
            birdBMP.y = -30;
            birdBMP.regX = 25;   // important to set origin point to center of your bitmap
            birdBMP.regY = 25; 
            birdBMP.snapToPixel = true;
            birdBMP.mouseEnabled = true;
            stage.addChild(birdBMP);
            box2d.createBird(birdBMP);

this. Now I'm trying to bind an event listener to this Bidmap object like this.

birdBMP.addEventListener("mousedown", function(evt){
    console.log("clicked");
});

But it doesn't work. I'm using same "demo.js" from that example. The only thing I change is the one above. Changing Bitmap to createjs.Bitmap and then add an eventHandler to the bitmap. Everything else is working fine, just can't add an eventHandler. Anyone have any idea about why this eventHandler isn't working?

Thank you.

Edit: Here is the demo.js from the link on top: http://www.luxanimals.com/tutorials/birds/js/demo.js

1

There are 1 best solutions below

1
On BEST ANSWER

I noticed that this demo is using an old EaselJS version that does not support addEventListener, but I also tested it with onPress and it doesn't work - since you have not invested a lot of time in this yet, I'd suggest you to check out the "official" EaselJS-Box2D example from the Sandbox on Github, which already features mouse-interaction:

Link: https://github.com/CreateJS/sandbox

Live example: http://sandbox.createjs.com/EaselJS_Box2dWeb/

(This is not a direct programmatical answer to your question, but I posted it as an answer, because the tutorial you are trying to adapt is outdated and doesn't work with the current standards of EaselJS and there are more up-to-date examples available)