0

Hallo tabbar supports item click event. However spark tabBar doesnot supports itemClick event.

is there way to listen itemclick event in SPARK TABBAR

thanks all

ketan
  • 19,129
  • 42
  • 60
  • 98
flex
  • 185
  • 5
  • 19

1 Answers1

1

Spark components inheriting from ListBase no longer dispatch ItemClick events. You can use the IndexChangeEvent event instead though. It has a property newIndex that tells you which is the newly selected item (or tab in this particular case).

<s:TabBar dataProvider="{dp}" change="trace('selected: ' + event.newIndex)" />

One big difference with the old ItemClick is that this event is only dispatched when the selected item actually changes (as opposed to whenever it is clicked). If you really want the behaviour of ItemClick back, you can create a custom ItemRenderer that dispatches an ItemClick event.


If you want to react on every click there are a few approaches. Here are two of them:

1./ Create a custom ItemRenderer that dispatches an ItemClick event.

.

public class TabBarButton extends ButtonBarButton {

    override public function initialize():void {
        super.initialize();
        addEventListener(MouseEvent.CLICK, fireItemClick);
    }

    private function fireItemClick(event:MouseEvent):void {
        owner.dispatchEvent(new ItemClickEvent(
            ItemClickEvent.ITEM_CLICK, false, false, null, itemIndex, null, data
        ))
    }

}

You can now use it like this:

<s:TabBar id="tabBar" dataProvider="{dp}" 
          itemRenderer="net.riastar.TabBarButton" />

tabBar.addEventListener(ItemClickEvent.ITEM_CLICK, onItemClick);

2./ Another approach would be to just listen for any click event on the TabBar and use event.target to find the clicked tab:

<s:TabBar dataProvider="{dp}" click="trace(event.target)" />
//traces tabBar.TabBarSkin1.dataGroup.TabBarButton1

Note that this is a direct answer to your question, but I actually don't think you should do this. In most cases IndexChangeEvent.CHANGE will do just fine.

RIAstar
  • 11,912
  • 20
  • 37
  • Thanks, am trying dispatch event, whenever user clicks on tabbar. Change event will not support this kind of behaviour. Could you please give some more detail how does itemrender helps in adding itemclik event – flex Apr 26 '12 at 15:08