Search code examples
actionscript-3apache-flexflex-spark

Trigger ButtonBar Click


I have a weird thing going on with my skins. I'm hoping to fix it by doing a workaround that involves triggering the click of a sparks buttonbar button, but I'm not exactly sure how to do that.

Here's my button bar code

<s:ButtonBar id="tabs" dataProvider="{vs}"
             skinClass="skins.hatchedbuttonbarskins.TabBarSkin" 
             depth="100" width="80%" visible="true" 
             bottom="0" horizontalCenter="0" height="25" />
<mx:ViewStack id="vs" width="95%" height="625" 
              borderVisible="true" horizontalCenter="0">
    <s:NavigatorContent width="80%" height="100%" 
                        label="My Label" 
                        skinClass="skins.lg.TabNavigatorContent">
        <lists:ListCenter myLists="{this}" myButtons="{tabs}"/>
    </s:NavigatorContent>
...

There are three more navigatorcontent objects after this one.

In ListCenter.mxml, I want to trigger a click of the tabs button bar buttons. Here's the action script call I'm making.

myButtons[1].dispatchEvent(new MouseEvent(MouseEvent.CLICK));

It's giving me the following error:

Error #1069: Property 1 not found on spark.components.ButtonBar and there is no default value.

How do I access the button objects?


Solution

  • I'm not sure what you are trying to achieve, but you can try to change the ButtonBar.selectedIndex like this:

    myButtons.selectedIndex = 1;
    

    If you really want to access buttons, then use:

    var btnBarBtn:ButtonBarButton = myButtons.dataGroup.getElementAt(0) as ButtonBarButton;
    

    Or you can describe your skin problem, maybe there is another way to solve it.