Setting the selected index of a Flex LinkBar control

The following example shows you how you can set the selected index of a LinkBar control in Flex by setting the selectedIndex property using MXML or ActionScript.

Full code after the jump.


<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<mx:Application xmlns:mx=""

    <mx:Array id="arr">
        <mx:Object label="One" />
        <mx:Object label="Two" />
        <mx:Object label="Three" />
        <mx:Object label="Four" />

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="selectedIndex:">
                <mx:HSlider id="slider"
                        maximum="{linkBar.dataProvider.length - 1}"
                        dataTipPrecision="0" />

    <mx:LinkBar id="linkBar"
            selectedIndex="{slider.value}" />


View source is enabled in the following example.

You can also set the selectedIndex property in ActionScript, as shown in the following snippet:


        private function slider_change(evt:SliderEvent):void {
            linkBar.selectedIndex = evt.value;

12 thoughts on “Setting the selected index of a Flex LinkBar control

  1. There is a bug, try to click on the LinkBar’s items then use the slider : several items can be selected !
    to be honnest, i fixed the problem by setting the ‘enabled’ property of each LinkButton to false, except the one that should be selected.

  2. It seems that linkBar.selectedIndex = some_value is not supported if the linkbar is not paired with a viewstack, which is also the implicit dataprovider, thus the issue mentioned above.
    It’s a bit of a pain…

  3. True this will not work “linkBar.selectedIndex = some_value”. To do this make your own custom linkbar let say call it myLinkBar



    And then in the itemClick (itemClick="myFunc(event)") do the following:-

    private function myFunc(event:ItemClickEvent):void
  4. Helps is I use the right tags… ;)

    &lt?xml version=”1.0″ encoding=”utf-8″?&gt
    &ltmx:LinkBar xmlns:mx=”” itemClick=”myFunc(event)”&gt


    import mx.controls.Button;

    private function myFunc(event:ItemClickEvent):void
    var n:int = this.numChildren;
    for (var i:int = 0; i


  5. I’m trying to remove all spacing between linkbar link buttons, I have a design that calls for the links to be stacked vertically with 5px of space between them, I’ve cleared out all padding, for the linkbuttonstyles, and removed vertical gap, and set separator width to zero. What am I missing it seems like this shouldn’t be that hard? Any help is much appreciated thanks!

  6. Try something like this….

    linkBar.selectedIndex = 2

    It works for ToggleButtonBar

Comments are closed.