Flash Builder 4.6 |删除 Child | s:TileGroup

Flash Builder 4.6 | Remove Child | s:TileGroup

我确定我遗漏了一些非常简单的东西,但是我在删除 s:Tilegroup 中的 VBox 时遇到了问题。 我无法删除它。作为测试,当我只添加到舞台时(而不是 s:TileGroup),我能够删除 VBox。下面的代码也展示了我正在研究的概念。

<fx:Script>
    <![CDATA[
        protected function removeVBOX(event:Event):void{
            var t:DisplayObject = DisplayObject(event.target);
            t.parent.removeChild(t);
        }

        private function addVbox() : void {
            var vbox :VBox = new VBox();
            vbox.addEventListener(MouseEvent.CLICK,removeVBOX);

            vbox.width = 400;
            vbox.height = 500;
            vbox.horizontalScrollPolicy = "off";
            vbox.verticalScrollPolicy = "off";

            vbox.setStyle("backgroundAlpha", 0.39);
            vbox.setStyle("backgroundColor",  0x000000);
            vbox.setStyle("paddingLeft",  "15");
            vbox.setStyle("paddingTop",  "15");
            vbox.setStyle("paddingRight",  "15");
            vbox.setStyle("paddingBottom",  "15");

            var sText :RichText = new RichText();
            var sText2 :RichText = new RichText();
            var sText3 :RichText = new RichText();

            sText.text = "Hello 1";
            sText2.text = "Hello 2";
            sText3.text = "Hello 3";    

            //addElement(vbox);
            table.addElement(vbox);
            vbox.addElement(sText);
            vbox.addElement(sText2);
            vbox.addElement(sText3);

        }

    ]]>
</fx:Script>

<s:Button x="743" y="767" label="Button" click="addVbox()"/>
<s:TileGroup id="table" x="152" y="81" width="627" height="650" horizontalAlign="center" horizontalGap="13"
             orientation="columns" requestedColumnCount="1" verticalAlign="middle" verticalGap="13" >
</s:TileGroup>

查看您的代码,我发现您按如下方式将 VBox 添加到 TileGroup:

table.addElement(vbox);

但是您正尝试使用 removeChild():

删除它

t.parent.removeChild(t);

add/remove 项 to/from Spark 容器的正确方法是 add/removeElement():

var t:IVisualElement = IVisualElement(event.target);
t.parent.removeElement(t);