A TabNavigator container creates and manages a set of tabs, which you use to navigate among its children. The children of a TabNavigator container are other containers. The TabNavigator container creates one tab for each child. When the user selects a tab, the TabNavigator container displays the associated child, as the following image shows:
The TabNavigator container is a child class of the ViewStack container and inherits much of its functionality. For complete reference information, see the Adobe Flex Language Reference.
You use the <mx:TabNavigator> tag to define a TabNavigator container. Only one child of the TabNavigator container is visible at a time. Users can make any child the selected child by selecting its associated tab or by using keyboard navigation controls. Whenever the user changes the current child, the TabNavigator container broadcasts a change event.
The TabNavigator container automatically creates a tab for each of its children and determines the tab text from the label property of the child, and the tab icon from the icon property of the child. The tabs are arranged left to right in the order determined by the child indexes. All tabs are visible, unless they do not fit within the width of the TabNavigator container.
If you disable a child of a TabNavigator container by setting its enabled property to false, you also disable the associated tab.
The following code creates the TabNavigator container in the image in TabNavigator container:
<?xml version="1.0"?>
<!-- containers\navigators\TNSimple.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:TabNavigator borderStyle="solid" >
<mx:VBox label="Accounts"
width="300"
height="150">
<!-- Accounts view goes here. -->
</mx:VBox>
<mx:VBox label="Stocks"
width="300"
height="150">
<!-- Stocks view goes here. -->
</mx:VBox>
<mx:VBox label="Futures"
width="300"
height="150">
<!-- Futures view goes here. -->
</mx:VBox>
</mx:TabNavigator>
</mx:Application>
The executing SWF file for the previous example is shown below:
You can also set the currently active child by using the selectedChild and selectedIndex properties inherited from the ViewStack container as follows:
For more information on the selectedChild and selectedIndex properties, including examples, see ViewStack navigator container.
You use the showEffect and hideEffect properties of the children of a TabNavigator container to specify an effect to play when the user changes the currently active child. The following example plays the WipeLeft effect each time the selected tab changes:
<?xml version="1.0"?>
<!-- containers\navigators\TNEffect.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:WipeLeft id="myWL"/>
<mx:TabNavigator>
<mx:VBox label="Accounts"
width="300"
height="150"
showEffect="{myWL}">
<!-- Accounts view goes here. -->
<mx:Text text="This is a text control."/>
</mx:VBox>
<mx:VBox label="Stocks"
width="300"
height="150"
showEffect="{myWL}">
<!-- Stocks view goes here. -->
<mx:Text text="This is a text control."/>
</mx:VBox>
<mx:VBox label="Futures"
width="300"
height="150"
showEffect="{myWL}">
<!-- Futures view goes here. -->
<mx:Text text="This is a text control."/>
</mx:VBox>
</mx:TabNavigator>
</mx:Application>
The executing SWF file for the previous example is shown below:
The default width and height of a TabNavigator container is the width and height of the first child. A TabNavigator container does not change size every time you change the active child.
You can use the following techniques to control the size of a TabNavigator container so that it displays all the components inside its children:
The method that you use is based on your application and the content of your TabNavigator container.
When a TabNavigator container has focus, Flex processes keystrokes as the following table describes:
|
Key |
Action |
|---|---|
|
Down Arrow Right Arrow |
Gives focus to the next tab, wrapping from last to first, without changing the selected child. |
|
Up Arrow Left Arrow |
Gives focus to the previous tab, wrapping from first to last, without changing the selected child. |
|
Page Down |
Selects the next child, wrapping from last to first. |
|
Page Up |
Selects the previous child, wrapping from first to last. |
|
Home |
Selects the first child. |
|
End |
Selects the last child. |
|
Enter Spacebar |
Selects the child associated with the tab displaying focus. |