0
votes

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

1
Nope. Use IndexChangeEventRIAstar
Spark tabar doesnot supports indexChangeEventflex
Yes it does: that change in the MXML notation is in fact an IndexChangeEvent.CHANGE.RIAstar
welll it doesn't dispatched each time u click on selected tabbar! right.flex
That's right. I've updated my answer to address this.RIAstar

1 Answers

1
votes

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.