Easeljs: show pointer cursor when mouse is on shape's bounds

user1972450 picture user1972450 · Jan 15, 2014 · Viewed 8.9k times · Source

I am trying to achieve something similar to the code below. When user is on the edge of a rectangle, the cursor points a pointer, otherwise cursor is an arrow.

     shape.graphics.beginStroke("#000").beginFill("#daa").drawRect(50, 150, 250, 250);
     shape.on("mousemove", function(evt) {
          if (isOnEdges(evt)) {
              evt.target.cursor = "pointer";
          } else {
              evt.target.cursor = "arrow";
          }
     });

Problems with the above code is:

  1. Shape doesn't have a mousemove handler
  2. how do i calculate if mouse is on the edge of a shape (isOnEdges function)

Answer

Lanny picture Lanny · Jan 15, 2014

You can simply set the cursor on the shape, and ensure that you enableMouseOver on the stage:

var shape = new Shape();
shape.graphics.beginStroke("#000").beginFill("#daa").drawRect(50, 150, 250, 250);
shape.cursor = "pointer";

stage.enableMouseOver();

EaselJS will automatically determine when you are over the shape's bounds.