Adding icons to a Flex TabNavigator control
I was trying to figure out how to add icons to a TabNavigator control today and ended up making this. The trick is that you actually add the icon on the TabNavigator control’s child containers and not on the TabNavigator itself. The example also has three tabs which each look at a different filtered view of an XML document (filtered using E4X).
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:XML id="model">
<records>
<record uuid="1" status="check" name="User 1" data="Data 1" />
<record uuid="2" status="warning" name="User 2" data="Data 2" />
<record uuid="3" status="warning" name="User 3" data="Data 3" />
<record uuid="4" status="critical" name="User 4" data="Data 4" />
<record uuid="5" status="check" name="User 5" data="Data 5" />
<record uuid="6" status="check" name="User 6" data="Data 6" />
<record uuid="7" status="warning" name="User 7" data="Data 7" />
<record uuid="8" status="critical" name="User 8" data="Data 8" />
</records>
</mx:XML>
<mx:Script>
<![CDATA[
[Bindable]
[Embed(source="assets/bulletCheck.png")]
private var BulletCheck:Class;
[Bindable]
[Embed(source="assets/bulletWarning.png")]
private var BulletWarning:Class;
[Bindable]
[Embed(source="assets/bulletCritical.png")]
private var BulletCritical:Class;
private const CHECK:String = "check";
private const WARNING:String = "warning";
private const CRITICAL:String = "critical";
]]>
</mx:Script>
<mx:TabNavigator width="400" height="200">
<mx:VBox label="Check" icon="{BulletCheck}">
<mx:DataGrid id="gridCheck"
width="100%"
height="100%">
<mx:columns>
<mx:DataGridColumn dataField="@name" />
<mx:DataGridColumn dataField="@data" />
</mx:columns>
<mx:dataProvider>
{model.record.(@status == CHECK)}
</mx:dataProvider>
</mx:DataGrid>
</mx:VBox>
<mx:VBox label="Warnings" icon="{BulletWarning}">
<mx:DataGrid id="gridWarning"
width="100%"
height="100%">
<mx:columns>
<mx:DataGridColumn dataField="@name" />
<mx:DataGridColumn dataField="@data" />
</mx:columns>
<mx:dataProvider>
{model.record.(@status == WARNING)}
</mx:dataProvider>
</mx:DataGrid>
</mx:VBox>
<mx:VBox label="Errors" icon="{BulletCritical}">
<mx:DataGrid id="gridCritical"
width="100%"
height="100%">
<mx:columns>
<mx:DataGridColumn dataField="@name" />
<mx:DataGridColumn dataField="@data" />
</mx:columns>
<mx:dataProvider>
{model.record.(@status == CRITICAL)}
</mx:dataProvider>
</mx:DataGrid>
</mx:VBox>
</mx:TabNavigator>
</mx:Application>
View source is enabled in the following example.
Peter deHaan
Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.
-
Add Widgets (Content Sidebar)
This is your Content Sidebar. Edit this content that appears here in the widgets panel by adding or removing widgets in the Content Sidebar area.
19 Responses to Adding icons to a Flex TabNavigator control
Leave a Reply Cancel reply
-
Categories
- Accordion
- AccordionHeader
- ActionScript
- AddChild
- AdvancedDataGrid
- Alert
- alpha
- Animate
- AnimateProperties
- Application
- Application (Spark)
- ArrayCollection
- BarChart
- baseColor
- beta
- beta1
- beta2
- Bitmap
- Bitmap/BitmapData
- BitmapData
- BitmapFill
- BitmapFill (Spark)
- BitmapGraphic
- BitmapImage
- BitmapImage (Spark)
- BitmapImageResizeMode
- Border (Spark)
- BorderContainer (Spark)
- Box
- BuildInfo
- Button
- Button (Spark)
- ButtonBar
- ButtonBar (Spark)
- ByteArray
- Camera
- Charting
- CheckBox
- CheckBox (Spark)
- ClassFactory
- CollectionEvent
- Color
- ColorPicker
- ColorUtil
- ComboBox
- ComboBoxArrowSkin
- Compiler
- Component
- Component (Spark)
- Configuration
- Container
- ContextMenu
- ContextMenuEvent
- ContextMenuItem
- CSSCondition
- CSSSelector
- CSSStyleDeclaration
- CurrencyFormatter
- CursorManager
- Data Binding
- DataGrid
- DataGrid (Spark)
- DataGridColumn
- Date
- DateBase
- DateChooser
- DateField
- DateFormatter
- Debugging
- DefaultComplexItemRenderer
- DefaultTileListEffect
- DropDownList
- DropDownList (Spark)
- DropDownListButtonSkin
- DropDownListSkin
- DropShadowFilter
- E4X
- Effects
- Ellipse
- EmailValidator
- Embed
- Event
- Fade
- FileFilter
- FileReference
- fill
- Filters
- Flash
- Flash Integration
- FlashVars
- Flex 3 SDK
- Flex Builder
- Flex Builder 3
- Flex SDK
- Flex4
- FLVPlayback
- FocusManager
- FontLookup
- Fonts
- Form
- Form (Spark)
- FormHeading (Spark)
- FormItem
- FormItem (Spark)
- Forms
- FTETextField (Spark)
- FullScreen
- FullScreenEvent
- FxAnimateColor
- FxButtonBar
- FxCheckBox
- FXG
- FxHScrollBar
- FxHSlider
- FxList
- FxNumericStepper
- FxRadioButton
- FxRotate3D
- FxScroller
- FxTextArea
- FxTextInput
- FxToggleButton
- FxVScrollBar
- FxVSlider
- getStyleDeclaration()
- GradientEntry
- Graphic (Spark)
- HBox
- HDividedBox
- HGroup (Spark)
- HorizontalLayout
- HorizontalList
- HSBColor (Spark)
- HScrollBar (Spark)
- HSlider
- HSlider (Spark)
- HTML template
- ID3Info
- Image
- Image (Spark)
- ImageSnapshot
- itemRenderer
- JointStyle
- Label
- Label (Spark)
- Legend
- LegendItem
- LigatureLevel
- Line
- LinearGradientStroke
- LineScaleMode
- LinkBar
- LinkButton
- List
- List (Spark)
- Menu
- MenuBar
- Metadata
- MetadataEvent
- Model
- Mouse
- MouseCursor
- MouseEvent
- Move
- Namespace
- NavigatorContent (Spark)
- needsSWF
- NetConnection
- NetStream
- Nightly Builds
- NumberBaseRoundType
- NumberFormatter
- NumberValidator
- NumericCompare
- NumericStepper
- NumericStepper (Spark)
- ObjectProxy
- ObjectUtil
- paddingLeft
- paddingRight
- Panel
- Panel (Spark)
- Parallel
- Path
- PieChart
- PieSeries
- PieSeriesItem
- PopUpAnchor (Spark)
- PopUpButton
- PopUpManager
- ProgrammaticSkin
- ProgressBar
- PropertyChangeEvent
- QName
- RadialGradient
- RadioButton
- RadioButton (Spark)
- RadioButtonGroup
- RadioButtonGroup (Spark)
- Rect
- RegExp
- Regular Expressions
- Repeater
- RichEditableText
- RichText
- RichText (Spark)
- RichTextEditor
- Rotate
- Rotate3D (Spark)
- Scroller (Spark)
- Sequence
- setStyle()
- SimpleText
- SimpleText (Spark)
- skinClass
- Slider
- SliderEvent
- SolidColor
- SolidColorStroke
- Sort
- SortField
- Sound
- SoundEffect
- Spinner (Spark)
- SpriteVisualElement (Spark)
- StageDisplayState
- States
- StringUtil
- StringValidator
- StyleManager
- Styles
- SWFLoader
- SWFObject
- System
- SystemManager
- TabBar
- TabBar (Spark)
- TabNavigator
- TabStopFormat
- Text
- Text Layout Framework (TLF)
- TextArea
- TextArea (Spark)
- TextBox
- TextConverter
- TextEvent
- TextFlow
- TextFlowUtil
- TextFormat
- TextGraphic
- TextInput
- TextInput (Spark)
- TextLayoutFormat
- TextView
- Themes
- TileLayout
- TileList
- TileOrientation
- Timer
- TitleWindow
- TitleWindow (Spark)
- TLF
- ToggleButton (Spark)
- ToggleButtonBar
- ToolTip
- Transition
- Tree
- TruncationOptions
- UIComponent
- UIFTETextField
- Updater
- URLLoader
- URLRequest
- URLUtil
- URLVariables
- ValidationResultEvent
- Validator
- Validators
- VBox
- VDividedBox
- Vector
- VerticalLayout
- VerticalLayout (Spark)
- VGroup (Spark)
- Video
- VideoDisplay
- VideoElement
- VideoElement (Spark)
- VideoEvent
- VideoPlayer (Spark)
- VideoPlayerScrubBar
- ViewStack
- VScrollBar (Spark)
- VSlider
- VSlider (Spark)
- XML
- XMLList
- XMLListCollection
- ZipCodeValidator
- ZipCodeValidatorDomainType
- Zoom
-
Articles
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
-
Meta


Very nice example – thanks for posting it. When I tried to download the source code I got a 404 error. I wanted to get the icons you used so I could run the example myself in FlexBuilder.
Bruce,
Sorry about that. I’ll try and reFTP that ZIP file and see if it uploads this time.
Peterd,
i need to put 10 labels in my tabNavigator and i need every names are visible!
thanks
Paulo
Paulo Jose,
You could try the SuperTabNavigator container from FlexLib: http://code.google.com/p/flexlib/wiki/ComponentList
I’m not sure if it supports multiple rows of tabs or not though.
Peter
Do you know how to move the icon’s to a stylesheet?
I have the following, but it doesn’t appear to work (the background style comes through though.
.greenTab { icon: Embed('/assets/green-dot.gif'); backgroundColor: '#cccccc'; } .redTab { icon: Embed('/assets/red-dot.gif'); backgroundColor: '#cccccc'; }-Sean
Sean,
I logged an enhancement request about making it easier to skin individual buttons on a ButtonBar control a while ago, http://bugs.adobe.com/jira/browse/SDK-17117.
The same workarounds may apply to the TabBar/TabNavigator controls as well, although you may need to use the
getTabAt()method, I believe.When I get some time, I’ll see if I can post the workarounds to SDK-17117 as full blog entries.
Hope that helps,
Peter
Hi,
Can we add link button @ place of icon ?
Thanks,
Prashant Shelke.
I want add the icon to right,i need you help
Pan,
I’m not sure if this is the best approach, but you could try and do something like this:
Peter
Did this work for anyone? I can’t get the icon to the right still…
Works for me. Just verified it again in Flex SDK 3.5.0.11086.
Peter
private function placeLabel():void{
setStyle and TextAlign should work …
for (var i:int = 0; i < linkTab.numChildren; i++) {
var tab:Tab = linkTab.getTabAt(i) as Tab;
tab.setStyle("textAlign","left");
}
}
I have been trying to animate those icons in the TabNavigator. Any idea on how to do that?
Thanks
I am trying to use icons loaded with my asset loading system (which is quite common-style), and I get a coercion error..
Basically, my Assets singleton class returns a class reference to an asset which is stored inside an external swf.
The assets are loaded, and I use the system everywhere in the project. for example
Now for use as icon, this approach doesnt seem to work. I get
Flex Error #1034: Type Coercion Failed: Cannot Convert TalentTabIconEconomy@6d40c41 to mx.core.IFlexDisplayObject
Will try to find a solution and post it here.
My example was supposed to be
<Image source="{Assets.getAsset('TalentTabIconEconomy')}"/>and i can’t seem to find a solution yet :(
@Jovica Aleksic,
What does your Assets class look like? Can you post the code here.
Peter
Heh, totally forgot about this entry. Long time no see :-)
Well, my Assets class is (overly) complicated and consists of several helper classes. It would be too much to post it here. Should somebody be interested, feel free to drop a mail at jovica.aleksic_at_loopmode.de.
However, the TabNavigator-with-icons situation became obsolete, because due to further project-specific complications I decided not to use the Flex TabNavigator, but create a “fake” custom tabNavigator using the usual containers like Canvas, Hbox etc.
Hi,
can we apply skin on the tabs with “degrafa”. are you you ever try with it.
anyway good example.
Tahir Alvi
@Tahir Alvi,
I’ve never used degrafa, sorry.
Peter