0

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?

Tristan Warner-Smith
  • 9,631
  • 6
  • 46
  • 75

1 Answers1

1

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()

olsn
  • 16,644
  • 6
  • 59
  • 65
  • 3
    Note that to get mouseover/mouseout events, you will need to enable mouse over on the Stage. It is a costly operation, so it's opt-in. `stage.enableMouseOver()` http://www.createjs.com/Docs/EaselJS/classes/Stage.html#method_enableMouseOver – Lanny Jul 09 '13 at 21:40