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.
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.
Would setting the mouseEnabled property of the custom cursor to false do essentially the same thing?
@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.
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;
}
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?