bottom uicomponent不接收鼠标事件

时间:2010-04-19 22:20:52

标签: flex actionscript

HI,

     I am sure this is very basic, however I am not able to find the solution. 

   I have a base ShapeContainer(UIComponent). I add a uicomponent which has mouse down listener to ShapeContainer. the listener works great.

当我在ShapeContainer上添加一个简单的精灵(绘制正方形)时,该侦听器不再起作用。

在代码中,如果我在下面的行中发表评论,那么事件监听器工作正常。

       **shapeContainer.addChildAt(square,1);**

我在顶级精灵上尝试了一些类似于mouseenabled = false的东西。             还试图添加addChildAt,但没有他们做任何帮助。

如何绘制形状并使事件监听器有效。

             

        protected function application1_creationCompleteHandler(event:FlexEvent):void
        {               

            var shapeContainer:UIComponent = new UIComponent();
            shapeContainer.x=100;
            shapeContainer.y=100;
            shapeContainer.width=200;
            shapeContainer.height=200;
            rawChildren.addChild(shapeContainer);


            var EventListenerShape:UIComponent = new UIComponent();

            EventListenerShape.x=100;
            EventListenerShape.y=100;
            EventListenerShape.width=200;
            EventListenerShape.height=200;

            EventListenerShape.graphics.clear();
            EventListenerShape.graphics.beginFill(0xf1f1f1, 0.1);
            EventListenerShape.graphics.drawRoundRect(0, 0, 200, 200, 10, 10);              
            EventListenerShape.alpha = 0;
            EventListenerShape.graphics.endFill();
            EventListenerShape.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownfunc);
            shapeContainer.addChild(EventListenerShape);


        var square:Sprite = new Sprite();
        square.graphics.lineStyle(4,0x00FF00);
        square.graphics.drawRect(0,0,20,20);
        square.mouseEnabled=false;
        shapeContainer.addChildAt(square,1);    



        }

        private function mouseDownfunc(e:MouseEvent){
            trace("mouse Down **");
        }

          
    ]]>
</mx:Script>

<mx:Canvas id="uic" width="100%" height="100%"   backgroundColor="0xFFFFFF">

</mx:Canvas>

2 个答案:

答案 0 :(得分:0)

尝试将方块的mouseEnabled mouseChildren设置为false。

答案 1 :(得分:0)

我的坏,这是一个小错误。我刚刚改变了方形的x,y。我必须分配0或评论以下2行。

EventListenerShape.x=100;
EventListenerShape.y=100;

谢谢

相关问题