我在创建动态标签时遇到问题 这是我的代码:
MXML:
<s:TabBar x="1" y="1" height="32" width="100%" dataProvider="{tabHolder}" chromeColor="#EF8B01"/>
<mx:ViewStack x="2" y="34" id="tabHolder" width="100%" height="214" creationPolicy="all">
<s:NavigatorContent label="Home" width="100%" height="100%">
<mx:Image x="6" y="8" height="181" width="402"/>
</s:NavigatorContent>
</mx:ViewStack>
为:
var newTab:NavigatorContent = new NavigatorContent();
newTab.label = "Dynamic";
var lab:Label = new Label();
lab.text = "Dynamic context";
newTab.addChild(lab);
tabHolder.addChild(newTab);
标签未添加,有什么问题?
答案 0 :(得分:4)
以下对我有用。我唯一改变的是使用addElement()
方法而不是addChild()
将标签添加到视图堆中。
<强> MXML:强>
<mx:Button id="myButton" label="Add Tab" click="myButton_clickHandler(event)" />
<s:TabBar x="1" y="31" height="32" width="100%" dataProvider="{tabHolder}" chromeColor="#EF8B01"/>
<mx:ViewStack x="2" y="64" id="tabHolder" width="100%" height="214" creationPolicy="all">
<s:NavigatorContent label="Home" width="100%" height="100%">
<mx:Image x="6" y="8" height="181" width="402"/>
</s:NavigatorContent>
</mx:ViewStack>
<强>的ActionScript:强>
protected function myButton_clickHandler(event:MouseEvent):void
{
var newTab:NavigatorContent = new NavigatorContent();
newTab.label = "Dynamic";
var lab:Label = new Label();
lab.text = "Dynamic context";
newTab.addElement(lab);
tabHolder.addElement(newTab);
}