flex TabNavigator 添加 删除 tab(解决添加之后tab没有选择bug)

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="getChildrens()">
<mx:Script>
<![CDATA[
import mx.events.ChildExistenceChangedEvent;
import mx.events.IndexChangedEvent;
import mx.events.FlexEvent;
import mx.controls.TabBar;
import mx.containers.Tile;
import mx.controls.Alert;
    var kc:int=0;
private function getChildrens():void
{
var cc:Canvas=new Canvas();
tabNav.addChild(cc);
for(var i:int=0;i<3;i++)
{
var canvas:Tile=new Tile();
canvas.id="canv"+i.toString();
for(var j:int=0;j<3;j++)
{
var bt1:Button=new Button();
bt1.label=i.toString()+"...."+j.toString();
canvas.addChild(bt1);
}
tabNav.addChildAt(canvas,i);
}
tabNav.removeChild(cc);
tabNav.selectedIndex=kc;
tabNav.addEventListener(IndexChangedEvent.CHANGE,ckTabNav)
}
private function ckTabNav(event:IndexChangedEvent):void
{
kc=tabNav.selectedIndex;
//Alert.show(kc.toString());
}
private function t():void
{
tabNav.removeAllChildren();
}

]]>
</mx:Script>
<mx:Panel x="43" y="87" width="0" height="0" layout="absolute" id="panel1" title="5555">
<mx:Canvas x="19" y="10" width="200" height="200" id="canvas1">
</mx:Canvas>
</mx:Panel>
<mx:TabNavigator id="tabNav" x="81" y="62" width="200" height="200">
</mx:TabNavigator>
<mx:Button x="178" y="320" label="removeall" click="t()"/>
<mx:Button x="494" y="320" label="Button" click="getChildrens()"/>

</mx:Application>

你可能感兴趣的:(xml,Flex)