当父级为mouseEnabled = false,mouseChildren = false时,MOUSE_OUT事件未在子级上触发

时间:2009-07-12 01:07:24

标签: flash actionscript-3 actionscript

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

我为子项添加了一个侦听器,用于MOUSE_OUT事件。

当我设置父级精灵mouseEnabled = false且mouseChildren = false时,如果我的鼠标位于子级精灵中,则不会对该子级触发MOUSE_OUT。

但是,当我移动鼠标时,MOUSE_OUT会被触发。如果我点击,也会触发MOUSE_OUT。如果我鼠标滚动,则不会触发MOUSE_OUT。

那么,这里发生了什么?

This is a related question


在研究了back2dos的代码之后,我发现我正在做的不同就是在设置mouseChildren = mouseEnabled = false之前调用stage.focus = null。我将舞台焦点设置为null以清除文本字段中闪烁的光标...有更好的方法吗?


这里是back2dos的修改代码。重现的步骤:单击文本字段,获取闪烁的光标。单击“按钮”,但不要在向下和向上之间移动鼠标。请注意光标不闪烁(好)。另请注意,按钮上的mouse_out事件未触发。直到你移动或点击鼠标。

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;
        }

    }
}

2 个答案:

答案 0 :(得分:2)

你的代码肯定有问题...我在这里有一个最小的设置:

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;
        }
    }
}
当你鼠标移开时,

应该变成绿色,再次变红,如果你鼠标移开......点击它,我的机器上的this.mouseChildren = this.mouseEnabled = false ...被禁用了,这会触发mouseOut(所以矩形变成再次红了)......这对我来说很有意义......点击时鼠标输出的东西对我来说是一个明确的指标,你必须在某个地方有一个bug ...你能不能尝试减少问题并张贴它?

格尔茨

back2dos

答案 1 :(得分:0)

尝试使用MouseEvent.ROLL_OVER