【问题标题】:Dynamically add a tab to actionscript TabBar将选项卡动态添加到 actionscript TabBar
【发布时间】:2014-08-08 19:39:11
【问题描述】:

我正在尝试在运行时向 actionscript TabBar 控件添加一个新选项卡。当我使用 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.

【问题讨论】:

    标签: dynamic actionscript tabbar


    【解决方案1】:
    <?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>
    

    希望对你有帮助!!!

    【讨论】:

      猜你喜欢
      • 2021-11-24
      • 2022-08-09
      • 2011-05-10
      • 2020-12-30
      • 2015-09-02
      • 2021-10-30
      • 2021-10-23
      • 2013-01-07
      • 2021-12-09
      相关资源
      最近更新 更多