The following example shows how you can set the data provider of a ButtonBar control in Flex to a ViewStack container.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/01/11/setting-the-data-provider-of-a-flex-buttonbar-control-to-a-viewstack-container/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:ButtonBar id="buttonBar"
            dataProvider="{viewStack}"
            buttonHeight="32" />

    <mx:ViewStack id="viewStack">
        <mx:VBox label="Button"
                icon="@Embed('assets/Button.png')"
                backgroundColor="white"
                width="480"
                height="60">
            <mx:Label text="Button..." />
        </mx:VBox>
        <mx:VBox label="ButtonBar"
                icon="@Embed('assets/ButtonBar.png')"
                backgroundColor="white"
                width="480"
                height="60">
            <mx:Label text="ButtonBar..." />
        </mx:VBox>
        <mx:VBox label="CheckBox"
                icon="@Embed('assets/CheckBox.png')"
                backgroundColor="white"
                width="480"
                height="60">
            <mx:Label text="CheckBox..." />
        </mx:VBox>
        <mx:VBox label="ColorPicker"
            icon="@Embed('assets/ColorPicker.png')"
                backgroundColor="white"
                width="480"
                height="60">
            <mx:Label text="ColorPicker..." />
        </mx:VBox>
    </mx:ViewStack>

</mx:Application>

View source is enabled in the following example.

 
Tagged with:
 
About The Author

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.

One Response to Setting the data provider of a Flex ButtonBar control to a ViewStack container

  1. Brij kishor says:

    Nice sample code but above sample code is not working for flex mobile project.How to create this viewStack functionality by Spark component.