removeChild使用不当?

时间:2011-10-17 17:48:51

标签: actionscript removechild

我只是想在双击

时从舞台上删除一个影片剪辑
package  {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import fl.motion.MotionEvent;

    public class Main extends MovieClip{

        var thingeh:Things;

        public function Main() {
            thingeh = new Things;
            stage.addEventListener(MouseEvent.CLICK, onClick);
            stage.addEventListener(MouseEvent.DOUBLE_CLICK, onDouble);

        }

        public function onClick(event:MouseEvent)
        {
            addChild(thingeh);

        }
        public function onDouble(event:MouseEvent)
        {
            if(thingeh)
            removeChild(thingeh);

        }
    }

}

1 个答案:

答案 0 :(得分:0)

public function onDouble(event:MouseEvent)
{
    if( thingeh && contains(thingeh) )
    {
        removeChild(thingeh);
    }
}

此外,您可能需要在构造函数中使用doubleClickEnabled = true

请注意,MouseEvent.CLICK会因MouseEvent.DOUBLE_CLICK事件而被解雇。