I have a sprite (circle) that I wish to drag, and when I mouse over it a custom cursor appears.
var circle = new Circle();
addChild(circle);
circle.x = circle.y = 150;
var customCursor = new OpenHandCursor();
addChild(customCursor);
customCursor.visible = false;
circle.addEventListener(MouseEvent.MOUSE_OVER, overCircle);
circle.addEventListener(MouseEvent.MOUSE_OUT, outCircle);
circle.addEventListener(MouseEvent.MOUSE_DOWN, downCircle);
circle.addEventListener(MouseEvent.MOUSE_UP, upCircle);
function overCircle(e:MouseEvent):void {
Mouse.hide();
customCursor.visible = true;
stage.addEventListener(Event.ENTER_FRAME, follow);
}
function outCircle(e:MouseEvent):void {
trace("outCircle()");
Mouse.show();
customCursor.visible = false;
stage.removeEventListener(Event.ENTER_FRAME, follow);
}
function downCircle(e:MouseEvent):void {
customCursor.closeHand();
e.currentTarget.startDrag();
}
function upCircle(e:MouseEvent):void {
customCursor.openHand();
stopDrag();
}
function follow(e:Event):void {
customCursor.x = mouseX;
customCursor.y = mouseY;
}
Functionally this works fine but note the trace in circleOut(). As I drag the circle around the stage (obviously with the mouse over and down on the circle at all times) the trace reveals that circleOut() fires continually – I’m assuming at the same rate as the frame rate but I’m not sure. Suffice it to say, it’s very rapid-fire.
Why is circlOut() not waiting for an actual MOUSE_OUT?
Thanks!
Tim