Flex 3: Tabbar event

Recently while working on an AIR app, I had to create some functionality when the user clicked on a different tab, therefore I wanted to simply check for the active tab using an event. Something that I have found was that as soon as you use a viewstack as a dataprovider no events will be sent. Which led me to the conclusion that it’s not possible to track which tab the user clicked.. UNTIL I came across the ItemClickEvent which was exactly the piece that I was searching for.

How to use the ItemClickEvent

 
import mx.events.ItemClickEvent;
 
private function tabChange(e:ItemClickEvent):void{
trace(e.label); //outputs the label of the selected tab
trace(e.item); //outputs the item in the dataprovider of the selected tab
trace(e.index); // outputs the index of the selected navigation item
}

and below the mxml tag for the tabbar component

<mx :TabBar id="navBar" x="10" y="125" dataProvider="viewstack1" themeColor="#648B9A"  selectedIndex="0" itemClick="tabChange(event)"/>

Actually pretty simple, but when reading throuh the docs, then you pretty quick think that it’s not possible.. although nothing is impossible ;)

Creative Commons License
The Flex 3: Tabbar event by Tiago's Weblog, unless otherwise expressly stated, is licensed under a Creative Commons Attribution 2.5 Switzerland License.
Leave a comment

1 Comments.

  1. A nice work good keep it up :grin:

Leave a Reply

Your email address will not be published.


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">