Search code examples
drag-and-dropeaseljscreatejs

EaselJS mouse / touch events not being triggered


I'm struggling to get any of the mouse events working with the latest easeljs library (easeljs-0.6.1.min.js).

I'm using TypeScript (the definition of which seems to be up to date).

My stage, container etc are set up as follows:

stage = new createjs.Stage("gameCanvas");
container = new createjs.Container();
stage.addChild(container);
createjs.Touch.enable(stage);

I then have my entity related code which looks like this:

Egg.prototype.wireUpEggForMovement = function () {
    Game.get().container.addChild(this.bitmap);

    this.bitmap.mousedown = function (evt) {
        var o = evt.target;

        Game.get().container.addChild(this.bitmap);
        var offset = { x: o.x - evt.stageX, y: o.y - evt.stageY };
        this.gamePosition = new Point(offset.x, offset.y);

        evt.onMouseMove = function (ev) {
            o.x = ev.stageX + offset.x;
            o.y = ev.stageY + offset.y;
        };
    };
    this.bitmap.mouseover = function (evt) {
        var o = evt.target;
        o.scaleX = o.scaleY = 1.2;
    };
    this.bitmap.mouseout = function (evt) {
        var o = evt.target;
        o.scaleX = o.scaleY = 1;
    };
};

this.bitmap, stage and container all exist.

None of the mouse events are triggered however.

Any ideas?


Solution

  • If you are using the mousedown-keyword you have to use it like this:

    this.bitmap.addEventListener('mousedown', function...)
    

    http://www.createjs.com/Docs/EaselJS/classes/Bitmap.html#method_addEventListener

    OR: If you want to set a listener-function via an attribute(which is deprecated), you would have to use .onPress = function... to get the mouse-down event. But since this is deprecated I suggest you use the addEventListener()