开发者

Flash - Only show message on load if user is not already over the movie

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 woul开发者_JS百科d 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?

Thanks


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:

package 
{
    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();
            addChild(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";

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

            }// end if

        }// end function

    }// end class

}// end package
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜