Custom cursor “bug” in ActionScript3
If you ever want to use a custom mouse cursor in AS3 (for say dragging) with rollover/rollout events toggling it (so it will only change the cursor for certain movie-clips), bear this in mind:
When the user moves the mouse to the right with a certain (slowish) speed, the (original) hidden mouse cursor will go over the custom cursor, so it will fire the rollout event. Then when Flash updates the custom cursor position, the original mouse cursor won`t be over the custom one anymore, so it fires the rollout event, thus the cursor blinks quite noticeably. And no, the event.updateAfterEvent() won`t help either.
The workaround for this is to add the MouseEvent.MOUSE_MOVE listener to the stage and watch the event.target in the handler function and toggle the custom cursor using that, so you can specify that Flash shouldn`t do the toggling (= keep the custom cursor on) when the mouse goes over it.
So it isn`t necessarily a Flash Player bug, because this behavior makes sense (the mouse updates much more frequently than the .swf), but well annoying to figure out anyway.
January 1st, 2008 at 6:19 am
I just offset my custom cursor by one pixel in x & y and it works fine. If you look closely, you can notice that rollover fires 1px too soon, but it’s much better than flickering rollover/rollouts. Thanks for posting this… thought I was the only one having that problem.
January 31st, 2008 at 1:44 am
Would setting the mouseEnabled property of the custom cursor to false do essentially the same thing?
March 16th, 2008 at 8:54 pm
@kms: that’s a good idea, much simpler to do
@rhtx: no, because the problem lies in the rollout event of the – say – draggable item triggering the cursor change. it happens because the hidden mouse cursor goes over the custom cursor image, which is just a “neutral” item like the stage, so it triggers the rollout as the cursor is not directly over the draggable item any more.
October 7th, 2008 at 2:48 pm
Hi,
Ive had the same problem, I have the MouseMove listener registered to the stage and the custom cursor tracks the coordinates of the mouse in the MouseMove handler function. I was still getting flickering occasionally over movieclips behaving like buttons.
I tried offsetting the reg of the movieclips inside the custom cursor MC and this has greatly reduced the frequency of the rollout event being fired, though it still happens now and then.
Im not sure if I understand what you were trying to say in the ‘workaround’ paragraph, would you be kind enough to have a look at my code to see if im on the right track?
Thanks Dan
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
initCursor();
function initCursor()
{
cursor.mouseEnabled = false;
Mouse.hide();
addChild(cursor);
}
function mouseMoveHandler(event:MouseEvent):void
{
cursor.x = mouseX;
cursor.y = mouseY;
event.updateAfterEvent();
cursor.visible = true;
}
October 7th, 2008 at 3:59 pm
hey Dan,
you can try this:
cursor.x = mouseX + 1;
cursor.y = mouseY + 1;
as i`m not sure if this is actually the same as offsetting the thing inside the movieclip.
otherwise what i was writing about is how to tackle the rollover/rollout problem, it shouldn`t really happen in your case at all.
one thing though, is there any specific reason why you`re setting the cursor to visible on every mouse movement?
January 4th, 2009 at 5:33 pm
Setting MouseEnabled from the custom mouse graphic to false -does- work, rhtx ^^
I have no idea why but it does work o.O maybe because the mouse-interactions of the movieclip are disabled, Flash doesn’t recognize it as “Going from one object to another” when you’re moving right and hovering over it
January 22nd, 2009 at 7:28 pm
If you’re ever attaching a linked movie clip (chock full of graphics on different frames) be sure to set mouseChildren = false in addition to mouseEnabled = false.
June 5th, 2009 at 8:56 pm
I just set in the custom mouse movieclip:
mouseEnable = false;
mouseChildren = false;
this does the trick