Hello,
I have a graphic replacing the mouse cursor and I’m having it so that when the user goes over a MC (called hitSquare in this case) the cursor graphic moves to a certain location on the stage, then returns to the location of the real mouse position. Here’s what I’ve been doing:
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE,follow);
function follow(evt:MouseEvent) {
cursorMC.visible = true;
cursorMC.x = mouseX;
cursorMC.y = mouseY;
}
stage.addEventListener(Event.MOUSE_LEAVE, hideCursor);
function hideCursor(evt:Event) {
cursorMC.visible = false;
}
// MOVIE CLIP SETTINGS
hitSquare.addEventListener(MouseEvent.MOUSE_OVER, whack);
function whack(evt:MouseEvent) {
hitSquare.removeEventListener(MouseEvent.MOUSE_OVER, whack);
stage.removeEventListener(MouseEvent.MOUSE_MOVE,follow);
Tweener.addTween(cursorMC, {delay:0.10, x:700, y:-20, onComplete:returnCursor, time:0.2, transition:"easeOutSine"});
me.play();
}
function returnCursor() {
cursorMC.y = -10;
Tweener.addTween(cursorMC, {x:mouseX, y:mouseY, time:0.5, onComplete:reInitialise});
}
function reInitialise() {
hitSquare.addEventListener(MouseEvent.MOUSE_OVER, whack);
stage.addEventListener(MouseEvent.MOUSE_MOVE,follow);
}
The problem with this is that during the 0.5 seconds that it takes the graphic to return to the mouse position, the user can still move the mouse, so it actually goes to different co-ordinates and when the user moves the mouse after the 0.5 is over, the cursor just jumps to the new location.
How can I make it so that the graphic smoothly follows the mouse, (even if it’s being moved and has to update in real time) and then returns to the standard mouse follow code (cursorMC.x = mouseX; etc) once it’s met its final destination?
I take it this requires some “mouse trail” code that gets removed once it’s caught up with the mouse. I’m just not sure how to go about it.
Any ideas? Thanks guys.