Detect the mouse's move from Movie

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.