如何判断鼠标光标是否位于使用鼠标坐标的组件上

如何判断鼠标光标是否位于使用鼠标坐标的组件上

本文介绍了如何判断鼠标光标是否位于使用鼠标坐标的组件上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在某个特定的组件上,我试图用鼠标事件的帮助来确定。

所以现在我有两个组件,比方说buttonA和buttonB。 ButtonA有一个监听器,它已经在监听鼠标事件。 ButtonB与ButtonA的边缘齐平。

我需要找出它的代码。这里有更多的细节:
$ b $ pre $ protected function _mouseOutHandler(event:MouseEvent):void
{
if (MOUSE IS OVER BUTTONB){

}

if(MOUSE IS OVER DROPDOWNB) {

}
}
}


解决方案

我最终做了什么(从上面的回复中得到灵感)是设置一个超时,让鼠标有时间旅行,然后在超时处理程序中使用hitTestPoint来检查鼠标是否在组件。这是代码:

  private var timeout:uint; 
$ b / **
*鼠标移出项目渲染器设置超时
* * /
保护函数_mouseOutHandler(event:MouseEvent):void {

if(data.subCategories.length> 0){
timeout = setTimeout(checkToClose,150);


$ b / **
*当鼠标移出下拉菜单时的句柄
* * /
保护函数_menuMouseOutHandler(event :MouseEvent):void {
checkToClose();

$ b / **
检查鼠标是否超出下拉类别渲染器
* /
public function checkToClose():void {
var point:Point;

clearTimeout(timeout);

//检查下拉是否打开
if(menu.dropDown){
point = localToGlobal(new Point(mouseX,mouseY));
menu.dropDown.addEventListener(MouseEvent.MOUSE_OUT,_menuMouseOutHandler,false,0,true);

//检查下拉菜单或类别渲染器
//是否关闭下拉菜单
if(!menu.dropDown.hitTestPoint(point.x,point.y )
&&!hitTestPoint(point.x,point.y)){
menu.dropDown.removeEventListener(MouseEvent.MOUSE_OUT,_menuMouseOutHandler);
menu.closeDropDown(false);
}
}
}


I'm trying to determine with the help of a mouse event if I'm over a specific component.

So right now I have two components, let's say buttonA and buttonB. ButtonA has a listener on it already listening for the mouse out event. ButtonB is flush against the edge of ButtonA.

I need to find out the code for it. Here is more details:

        protected function _mouseOutHandler(event:MouseEvent):void
        {
            if (data.subCategories.length>0)
            {
                if (MOUSE IS NOT OVER BUTTONB) {

                }

                if (MOUSE IS OVER DROPDOWNB) {

                }
            }
        }
解决方案

What I ended up doing (with inspiration from the above replies) is setting a timeout to give the mouse time to travel and then in that timeout handler using hitTestPoint to check if the mouse is over either components. Here is the code:

        private var timeout:uint;

        /**
         * On mouse out of item renderer set timeout
         * */
        protected function _mouseOutHandler(event:MouseEvent):void {

            if (data.subCategories.length>0) {
                timeout = setTimeout(checkToClose, 150);
            }
        }

        /**
         * Handles when mouse moves out of drop down
         * */
        protected function _menuMouseOutHandler(event:MouseEvent):void {
            checkToClose();
        }

        /**
         * Check if mouse is out of drop down and category renderer
         * */
        public function checkToClose():void {
            var point:Point;

            clearTimeout (timeout);

            // check if drop down is open
            if (menu.dropDown) {
                point = localToGlobal(new Point(mouseX, mouseY));
                menu.dropDown.addEventListener(MouseEvent.MOUSE_OUT, _menuMouseOutHandler, false, 0, true);

                // check if we are over drop down or category renderer
                // if not close dropdown
                if (!menu.dropDown.hitTestPoint(point.x, point.y)
                    && !hitTestPoint(point.x, point.y)) {
                    menu.dropDown.removeEventListener(MouseEvent.MOUSE_OUT, _menuMouseOutHandler);
                    menu.closeDropDown(false);
                }
            }
        }

这篇关于如何判断鼠标光标是否位于使用鼠标坐标的组件上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 01:44