MOUSE_OUT事件不触发对孩子当父将mouseEnabled =虚假,mouseChildren =假虚假、事件、孩子、MOUSE_OUT

2023-09-09 21:32:29 作者:初吻给了烟

我做一个精灵,然后添加一个子精灵。

我添加一个监听到孩子MOUSE_OUT事件。

如果我的鼠标是孩子精灵,当我设置父精灵的mouseEnabled =虚假和mouseChildren =假,MOUSE_OUT不会触发对孩子。

但后来,当我移动鼠标,MOUSE_OUT被解雇的孩子。 MOUSE_OUT还解雇了,如果我点击。如果我鼠标滚轮MOUSE_OUT不会触发。

那么,到底是怎么回事?

This是一个相关的问题。

在学习back2dos'code,我发现我在做什么不同的呼唤stage.focus = NULL之前设置mouseChildren =将mouseEnabled =虚假的。我设置阶段焦点到空以清除闪烁的光标从一个文本字段... ...有没有更好的方式来做到这一点?

幼儿园砍人事件再发,孩子呆住了跑不动怎么办

下面是back2dos修改code。重现步骤:单击文本字段,获得闪烁的光标。点击按钮,但不移动鼠标向下和向上的。注意光标不闪烁(好)。还注意到,按钮上的MOUSE_OUT事件不会被触发。直到您移动或单击鼠标。

 包{
    导入flash.display使用*。
    进口flash.events *。
    进口flash.geom.ColorTransform;
    公共类测试扩展Sprite {
        私人VAR孩子:雪碧
        公共功能测试(){
                this.addChild(子=新的Sprite());
                child.graphics.beginFill(为0xFF0000);
                child.graphics.drawRect(0,0,100,20);
                child.addEventListener(MouseEvent.CLICK,的onClick);
                child.addEventListener(的MouseEvent.MOUSE_OUT,onOut);
                child.addEventListener(的MouseEvent.MOUSE_OVER,onOver);


    TF =新的TextField();
    tf.backgroundColor = 0xFF00AA;
    tf.background = TRUE;
    tf.type =为TextFieldType.INPUT;
    tf.text =哟;
    tf.y = 100;
    this.addChild(TF);
        }
        私有函数onOver(E:的MouseEvent):无效{
                child.transform.colorTransform =新的ColorTransform(0,0,0,1,0,为0xFF);
        }
        私有函数onOut(E:的MouseEvent):无效{
                child.transform.colorTransform =新的ColorTransform();
        }
        私有函数的onClick(E:的MouseEvent):无效{
            //尝试在这里...
            stage.focus = NULL;
                this.mouseChildren = this.mouseEnabled = FALSE;
                //或尝试在这里...
                //stage.focus = NULL;
        }

    }
}
 

解决方案

一定有什么不对您的code ...我有一个最低的设置位置:

 包{
    导入flash.display使用*。
    进口flash.events *。
    进口flash.geom.ColorTransform;
    公共类测试扩展Sprite {
    私人VAR孩子:雪碧
    公共功能测试(){
    this.addChild(子=新的Sprite());
    child.graphics.beginFill(为0xFF0000);
    child.graphics.drawRect(0,0,100,20);
    child.addEventListener(MouseEvent.CLICK,的onClick);
    child.addEventListener(的MouseEvent.MOUSE_OUT,onOut);
    child.addEventListener(的MouseEvent.MOUSE_OVER,onOver);
    }
    私有函数onOver(E:的MouseEvent):无效{
    child.transform.colorTransform =新的ColorTransform(0,0,0,1,0,为0xFF);
    }
    私有函数onOut(E:的MouseEvent):无效{
    child.transform.colorTransform =新的ColorTransform();
    }
    私有函数的onClick(E:的MouseEvent):无效{
    this.mouseChildren = this.mouseEnabled = FALSE;
    }
    }
}
 

应该变为绿色,当你的鼠标过来,红了起来,如果你的鼠标了...上点击,它被禁止与 this.mouseChildren = this.mouseEnabled = FALSE ...我的机器上,这会触发的mouseout(使矩形变成红色了)......这对我来说很有意义......并让鼠标出局的事情,当点击,是一个明确的指示给我,你必须在某个地方有一个bug ......你能尽量减少问题,并张贴?

I make a sprite, then add a child sprite.

I add a listener to the child for MOUSE_OUT events.

If my mouse is in the child sprite when I set the parent sprite mouseEnabled=false and mouseChildren=false, MOUSE_OUT is not fired on the child.

But then, when I move the mouse, MOUSE_OUT is fired on the child. MOUSE_OUT is also fired if I click. MOUSE_OUT is not fired if I mousewheel.

So, what's going on here?

This is a related question.

After studying back2dos' code, I discovered what I am doing differently is calling stage.focus = null just before setting mouseChildren = mouseEnabled = false. I am setting the stage focus to null to clear the blinking cursor from a textfield... is there a better way to do this?

here is back2dos' modified code. steps to reproduce: click the textfield, get the blinking cursor. click the "button", but don't move the mouse between down and up. note the cursor is not blinking (good). also note that the mouse_out events on the button have not fired. until you move or click the mouse.

package  {
    import flash.display.*;
    import flash.events.*;
    import flash.geom.ColorTransform;
    public class Test extends Sprite {
        private var child:Sprite
        public function Test() {
                this.addChild(child = new Sprite());
                child.graphics.beginFill(0xFF0000);
                child.graphics.drawRect(0, 0, 100, 20);
                child.addEventListener(MouseEvent.CLICK, onClick);
                child.addEventListener(MouseEvent.MOUSE_OUT, onOut);
                child.addEventListener(MouseEvent.MOUSE_OVER, onOver);


    	tf = new TextField( );
    	tf.backgroundColor = 0xFF00AA;
    	tf.background = true;
    	tf.type = TextFieldType.INPUT;
    	tf.text = "yo";
    	tf.y = 100;
    	this.addChild( tf );
        }
        private function onOver(e:MouseEvent):void {
                child.transform.colorTransform = new ColorTransform(0, 0, 0, 1, 0, 0xFF);
        }
        private function onOut(e:MouseEvent):void {
                child.transform.colorTransform = new ColorTransform();
        }
        private function onClick(e:MouseEvent):void {
            //try it here...
            stage.focus = null;
                this.mouseChildren = this.mouseEnabled = false;
                //or try it here...
                //stage.focus = null;
        }

    }
}

解决方案

there must be something wrong with your code ... i have a minimum setup here:

package  {
    import flash.display.*;
    import flash.events.*;
    import flash.geom.ColorTransform;
    public class Test extends Sprite {
    	private var child:Sprite
    	public function Test() {
    		this.addChild(child = new Sprite());
    		child.graphics.beginFill(0xFF0000);
    		child.graphics.drawRect(0, 0, 100, 20);
    		child.addEventListener(MouseEvent.CLICK, onClick);
    		child.addEventListener(MouseEvent.MOUSE_OUT, onOut);
    		child.addEventListener(MouseEvent.MOUSE_OVER, onOver);
    	}
    	private function onOver(e:MouseEvent):void {
    		child.transform.colorTransform = new ColorTransform(0, 0, 0, 1, 0, 0xFF);
    	}
    	private function onOut(e:MouseEvent):void {
    		child.transform.colorTransform = new ColorTransform();
    	}
    	private function onClick(e:MouseEvent):void {
    		this.mouseChildren = this.mouseEnabled = false;
    	}
    }
}

should turn green, when you mouse over, and red again, if you mouse out ... on click, it is disabled with this.mouseChildren = this.mouseEnabled = false ... on my machine, this triggers mouseOut (so the rectangle turns red again) ... this makes sense to me ... and the thing with getting mouse outs when clicking, is a definite indicator to me, you must be having a bug somewhere ... could you try to reduce the problem and post it?