Thursday, January 15, 2009

Flex Super Tab Navigator

So I have this dashboard project I'm working on. What I am trying to do is have a TabNavigator that is about half the screen, but give it a maximize button, so that if clicked it fills the whole screen. Sounds easy enough, I've done it with a Panel, but unfortunately it seemed a little too tricky for me and my high design : moderate coding skills. So to Google I went.

You know what annoys me? People who blog about this kind of thing, show the awesome component they created, and don't share even a bit of code. That's what I found. Ugh. I did however discover that flexLib has something called a SuperTabNavigator. The SuperTabNavigator has a close button on each tab, so I figured, maybe I can extend this, better than starting from scratch. It wasn't even as difficult as extending it. It is actually pretty easy to customize. Yay for flexLib.

Here are some actual CODE EXAMPLES of what I did.

First you need the flexLib library., add it by referencing the swc file in your project's library path, like you would Cairngorm.

First here's the SuperTabNavigator, which I placed inside a Canvas.

<code:SuperTabNavigator id="mySuperTabNav"
width="100%" height="50%"
<mx:VBox label="testing"/>

Here is the code for the maxClick method.

private function maxClick(event:SuperTabEvent):void
//This stops the default close action from happening
//Make sure the tab that was clicked is the one that is selected
event.currentTarget.selectedIndex = event.tabIndex;

//Put your max/restore tab code here!
/*example: mySuperTabNav.y = 0;
mySuperTabNav.percentHeight = 100;*/

Now... it wouldn't be very user friendly if clicking a close button maximizes the tab navigator, now would it? So through CSS we need to change the icon/button on the tab. Now this is kind of odd, I found this here:
tab-style-name: customTabMax;
tab-close-button-style-name: maxIconButton;

Here's a link to the documentation:

See my Sample (right click to view source)


Rickardo Avila said...

Thanks ANG for your customization. A off-topic question : are u know some program free to convert a image to SVG file. I need that for use a Degrafa lib for create a image since code. Thanks again

Anonymous said...

Thanks ANG, this was exactly what I needed to do as well, except mine was for a help icon in the tab that displays a tooltip like dialog.