Take the 2-minute tour ×

I have a flash movie, that shows a message to a user when it first loads up. When the users mouse enters the stage or moves the mouse the message disappears. However I would like to hide the message if the users mouse starts over the flash movie on the page load. Is this possible or does it need an interaction first?


share|improve this question
add comment

1 Answer

You can create a Rectangle object that has the same x, y, width and height values as the stage's. Then you create a condition(if statement) that checks to see if the Rectangle object contains the stage's mouseX and mouseY values upon initiation of your application. The following is a simple test to this:

    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Rectangle;
    import flash.text.TextField;

    public class Main extends Sprite 

        public function Main():void 
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);

        }// end function

        private function init(e:Event = null):void 
            removeEventListener(Event.ADDED_TO_STAGE, init);

            var textField:TextField = new TextField();

            var stageRect:Rectangle = new Rectangle(stage.x, stage.y, stage.stageWidth, stage.stageHeight);

            if (stageRect.contains(stage.mouseX, stage.mouseY))
                textField.text = "mouse is inside stage upon initiation";

                textField.text = "mouse is outside stage upon initiation";

            }// end if

        }// end function

    }// end class

}// end package
share|improve this answer
hi thanks for the reply but this doesn't seem to work once I embed it into a webpage, even using your example above. Any ideas? –  TommyBs Apr 13 '11 at 14:45
I think you probably need to set the focus of the flash first using javascript or jquery to be sure it will read the mouse when it has loaded. –  Neil Jun 6 '11 at 14:14
add comment

Your Answer


