Fleming Slone
Fleming Slone

Reputation: 177

Stopping Mouse Events In EaselJS

What is the best way to prevent an event handler from being fired in easelJS? In other projects I would use e.stopPropagation but that doesn't seem to work in easelJS.

The issue is that I am working with a library that uses easelJS and has a "pressmove" event handler to enable drag and drop. I'd like to prevent this handler from being fired if a modifier key, like ctrl or shift, is being held when the event is triggered. After checking whether a modifier is being held I would ideally then be able to trigger the original pressmove handler if need be.

Upvotes: 0

Views: 931

Answers (1)

Lanny
Lanny

Reputation: 11294

The stopPropagation method prevents an event from being bubbled, not fired. You can use stopImmediatePropagation to prevent other listeners at the same level from receiving the event after you (behaviour will depend on the order of events).

Ideally if you have a condition where you want to prevent a behavior, then look that up in your event handler, and conditionally handle the behaviour.

obj.on("pressmove", function(e) {
  if (someCondition) {
    doSomething();
  }
});

You can also toggle mouseEnabled to prevent an object from responding to mouse events (and mouseChildren if you want to block events on children of a container).

obj.mouseEnabled = false;

Hope that helps.

Upvotes: 1

Related Questions