Tab切换
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication 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;
import mx.events.ItemClickEvent;
import mx.controls.tabBarClasses.Tab;
protected function tabBar_creationComplete(event:FlexEvent):void
{
var colorArr:Array = ["red", "haloOrange", "yellow", "haloGreen", "haloBlue"];
var color:String;
var tab:Tab;
var idx:uint;
var len:uint = tabBar.dataProvider.length;
for(idx=0;idx<len;idx++){
var i:int=idx%colorArr.length;
color=colorArr[i];
tab = Tab(tabBar.getChildAt(idx));
tab.setStyle("fillColors", [color, "white"]);
tab.setStyle("fillAlphas", [1.0, 1.0]);
tab.setStyle("backgroundColor", color);
}
}
protected function tabBar_itemClick(event:ItemClickEvent):void
{
viewStack.selectedIndex=event.index;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<fx:Array id="arr">
<fx:Object label="Red" />
<fx:Object label="Orange" />
<fx:Object label="Yellow" />
<fx:Object label="Green" />
<fx:Object label="Blue" />
</fx:Array>
</fx:Declarations>
<s:layout>
<s:VerticalLayout gap="5"/>
</s:layout>
<mx:TabBar id="tabBar" dataProvider="{arr}" creationComplete="tabBar_creationComplete(event)"
itemClick="tabBar_itemClick(event)"/>
<mx:ViewStack id="viewStack" width="{tabBar.width}" styleName="plain">
<mx:VBox id="redVBox" width="100%" height="100">
<s:Label text="Red VBox"/>
</mx:VBox>
<mx:VBox id="orangeVBox" width="100%" height="100">
<mx:Label text="Orange VBox" />
</mx:VBox>
<mx:VBox id="yellowVBox" width="100%" height="100">
<mx:Label text="Yellow VBox" />
</mx:VBox>
<mx:VBox id="greenVBox" width="100%" height="100">
<mx:Label text="Green VBox" />
</mx:VBox>
<mx:VBox id="blueVBox" width="100%" height="100">
<mx:Label text="Blue VBox" />
</mx:VBox>
</mx:ViewStack>
</s:WindowedApplication>