关闭

Flex 中鼠标进出框体的事件

标签: flexfunction2010
1278人阅读 评论(0) 收藏 举报
分类:

利用Rectangle的contains或者containsPoint方法,得知鼠标 是否在Rectangle所表示的矩形范围内:

 

 

 

//rollover指示ROLL_OVER事件,ROLL_OUT事件,rect用于检测的Rectangle,overPoint用于检测MOUSE_MOVE事件
var rollover : Boolean = false;
var rect : Rectangle = new Rectangle(0,0,200,300);
var overPoint : Point;       
addEventListener(Event.ENTER_FRAME, enterFrameHandler);

               private function enterFrameHandler(event : Event) : void {
                        var mousePoint : Point = new Point(stage.mouseX, stage.mouseY);
                        if(rect.containsPoint(mousePoint)) {
                        //鼠标进入rect范围
                                if(!rollover){
                                        //鼠标首次进入rect
                                        rollover = true;
                                        overPoint = mousePoint;
                                        trace("ROLL_OVER");
                                }else{
                                        //鼠标在rect内移动
                                        if(overPoint && Point.distance(overPoint, mousePoint) != 0){
                                                overPoint = mousePoint;
                                                trace("MOUSE_MOVE");
                                        }
                                }
                        }else{
                         //鼠标移出rect范围
                                if(rollover){
                                //鼠标首次移出rect
                                        rollover = false;
                                        trace("ROLL_OUT");
                                }
                        }
                }

 


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wkyb608/archive/2010/12/03/6051866.aspx

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:75971次
    • 积分:1379
    • 等级:
    • 排名:千里之外
    • 原创:46篇
    • 转载:12篇
    • 译文:0篇
    • 评论:15条
    文章分类
    最新评论