PDA

View Full Version : Custom cursor trouble..?



jerry
May 28th, 2007, 09:06 AM
Hi there

I'm trying to do a simple custom cursor setup - but by some stange reason, the MouseEvent.MOUSE_OUT triggeres not only on mouseOut, but also during the mouseMove event (not constantly though) - try moving the mouse in circles, and then keep an eye on the trace output..

Can someone tell me whats wrong..?


import flash.ui.Mouse;

var target:DisplayObjectContainer = this;

var plane:Sprite = new Sprite();
plane.graphics.beginFill(0xCCCC);
plane.graphics.drawRect(0,0,400,300);

var cursor:Sprite = new Sprite();
cursor.graphics.beginFill(0x0);
cursor.graphics.drawRect(0,0,10,10);
cursor.visible = false;

target.addChild(plane);
target.addChild(cursor);

plane.addEventListener(MouseEvent.MOUSE_OVER, handleMouseOver);
plane.addEventListener(MouseEvent.MOUSE_OUT, handleMouseOut);

function handleMouseOver(e:MouseEvent):void {
trace("handleMouseOver");
Mouse.hide();
plane.addEventListener(MouseEvent.MOUSE_MOVE, moveCursor);
}

function moveCursor(e:MouseEvent):void {
trace("moveCursor");
cursor.x = e.localX;
cursor.y = e.localY;
e.updateAfterEvent();
cursor.visible = true;
}

function handleMouseOut(e:MouseEvent):void {
trace("handleMouseOut");
Mouse.show();
plane.removeEventListener(MouseEvent.MOUSE_MOVE, moveCursor);
cursor.visible = false;
}

jerry
May 28th, 2007, 09:30 AM
OK - figured it out - needed to set the mouseEnabled property to false:

cursor.mouseEnabled = false;

;)

rmj134
June 25th, 2007, 03:38 PM
this is good to know. I had the same problem. after linking an MC from the library or using an MC from the stage, when I would roll over a button, the rollover state of the button would blink. linking bitmap data from the library would not cause the problem.

I wonder why Adobe didn't feel the need to include that line in their "custom cursor" example?!?!

lightscience
June 25th, 2007, 03:55 PM
yeah this is extremely useful to me as well.

i succeeded with the cursor thing but it was in a much more roudabout way. at the time i couldn't find anything so direct as this to help me... very good to know for next time!