In earlier versions of AS, you cannot check whether the mouse is still in Flash Movie. Therefore, the video cannot detect whether the user is following the current Movie. Another problem is that if a custom mouse style is used, after the mouse is removed from the Movie, the custom mouse remains on the video, the current mouse position cannot be correctly displayed.
Now,AS3It allows you to capture the mouse moving out of Movie by listening to the mouseLeave action of the stage. MouseLeave is executed when the mouse moves out of Movie. However, there is no mouseEnter event, but you can set it by using mouseMove.
The following example uses a box as the custom mouse:
Package {
Import flash. display. Sprite;
Import flash. events. Event;
Import flash. events. MouseEvent;
Import flash. ui. Mouse;
Public class Test extends Sprite {
Private var cursor: Sprite = new Sprite ();
Public function Test (){
Cursor. graphics. beginFill (0xFF );
Cursor. graphics. drawRect (0, 0, 25, 25 );
AddChild (cursor );
Stage. addEventListener (Event. MOUSE_LEAVE, cursorHide );
Stage. addEventListener (MouseEvent. MOUSE_MOVE, cursorFollow );
Mouse. hide ();
}
Public function cursorHide (evt: Event): void {
Cursor. visible = false;
}
Public function cursorFollow (evt: MouseEvent): void {
If (! Cursor. visible) cursor. visible = true;
Cursor. x = stage. mouseX;
Cursor. y = stage. mouseY;
Evt. updateAfterEvent ();
}
}
}
When the mouse leaves Movie, the mouse pointer is hidden. When the mouse moves to Movie again, mouseMove is executed and the mouse is displayed.