Dynamic 向actionscript选项卡栏动态添加选项卡

Dynamic 向actionscript选项卡栏动态添加选项卡,dynamic,actionscript,tabbar,Dynamic,Actionscript,Tabbar,我试图在运行时向actionscript选项卡栏控件添加一个新选项卡。使用addChild()将选项卡添加到选项卡栏时,在运行时会出现异常: Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one. 但是,当我尝试改用addElement()时,在编译时出现了一个错误: 1061: Call to a possibly unde

我试图在运行时向actionscript选项卡栏控件添加一个新选项卡。使用addChild()将选项卡添加到选项卡栏时,在运行时会出现异常:

Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.
但是,当我尝试改用addElement()时,在编译时出现了一个错误:

1061: Call to a possibly undefined method addElement through a reference with static type spark.components:TabBar.

愿这对你有帮助

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               width="100%"
               height="100%">
<fx:Script>
    <![CDATA[
        import mx.events.FlexEvent;

        private var _lastAddedNumber:int = 1;

        protected function btnAddNewTab_clickHandler(event:MouseEvent):void
        {
            tabby.dataProvider.addItem('New '+_lastAddedNumber);
            _lastAddedNumber++;
        }
    ]]>
</fx:Script>
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<mx:Button id="btnSave"
           click="btnAddNewTab_clickHandler(event)"
           label="Add New Tab"/>

<mx:Form top="50">
    <mx:FormItem label="tabWidth:">
        <s:HSlider id="slider"
                   minimum="40"
                   maximum="120"
                   value="100"/>
    </mx:FormItem>
</mx:Form>

<s:TabBar id="tabby"
          horizontalCenter="0"
          verticalCenter="0">
    <s:layout>
        <s:HorizontalLayout gap="-1"
                            columnWidth="{slider.value}"
                            variableColumnWidth="false"/>
    </s:layout>
    <s:dataProvider>
        <s:ArrayList source="[red,orange,yellow,green,blue]"/>
    </s:dataProvider>
</s:TabBar></s:Application>