将选项卡动态添加到 actionscript TabBar
Posted
技术标签:
【中文标题】将选项卡动态添加到 actionscript TabBar【英文标题】:Dynamically add a tab to 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.
【问题讨论】:
【参考方案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"
>
<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>
希望对你有帮助!!!
【讨论】:
以上是关于将选项卡动态添加到 actionscript TabBar的主要内容,如果未能解决你的问题,请参考以下文章
PyQt5 动态将 QFormLayouts 添加到 QTabWidget 的选项卡中