开发者

Listener does not react when pressing on text (ActionScript)

开发者 https://www.devze.com 2023-03-26 15:08 出处:网络
I want to add to custom MovieClip MouseEvent listener. MovieClip contains some text. When pressing on the part of MovieClip that contains text, listener does not react. How can I change that? I want t

I want to add to custom MovieClip MouseEvent listener. MovieClip contains some text. When pressing on the part of MovieClip that contains text, listener does not react. How can I change that? I want the whole MovieClip to be clickable. Thank you开发者_JAVA技巧 in advance.


MovieClip has a property mouseChildren, which means that every event is send only to this container, and not to it's child elements: myMovieClip.mouseChildren = false;


package
{
    import flash.display.Sprite;
    import com.*;
    import flash.text.TextField;
    import flash.events.MouseEvent;

    public class Chk extends Sprite
    {
        private var ba:Ball;
        private var txt:TextField;
        public function Chk():void
        {
            ba=  new Ball(50, 0xf0fff00, 1);
            txt = new TextField();
            txt.text = "HI";
            ba.addChild(txt);
            addChild(ba);
            ba.buttonMode = true;
            ba.mouseChildren = false;
            ba.x = stage.stageWidth/2;
            ba.y = stage.stageWidth/2;
            ba.addEventListener(MouseEvent.CLICK, action);
        }
        private function action(e:MouseEvent):void
        {
            trace("clicked");
        }
    }
}

.......

0

精彩评论

暂无评论...
验证码 换一张
取 消