Hiding specific items in a data provider based on the current application state in Flex Gumbo

The following example shows how you can toggle specific strings based on the Flex Gumbo application’s current state by using the includeIn and excludeFrom attributes on the String object.

For more information see “Exploring the new states syntax in Flex Gumbo” and the “Enhanced States Syntax – Functional and Design Specification” page at opensource.adobe.com.

Full code after the jump.

To use the following code, you must have Flash Player 10 and a Flex Gumbo SDK installed in your Flex Builder 3. For more information on downloading and installing the Gumbo SDK into Flex Builder 3, see “Using the beta Gumbo SDK in Flex Builder 3”.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/02/24/hiding-specific-items-in-a-data-provider-based-on-the-current-application-state-in-flex-gumbo/ -->
<FxApplication name="String_includeIn_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        backgroundColor="white">

    <states>
        <State name="one" />
        <State name="two" />
        <State name="three" />
    </states>

    <ApplicationControlBar>
        <Form styleName="plain">
            <FormItem label="currentState:">
                <Label text="{currentState}" />
            </FormItem>
            <FormItem direction="horizontal">
                <FxButton label="State one"
                        click="currentState='one';" />
                <FxButton label="State two"
                        click="currentState='two';" />
                <FxButton label="State three"
                        click="currentState='three';" />
            </FormItem>
        </Form>
    </ApplicationControlBar>

    <FxList id="list"
            horizontalCenter="0"
            bottom="40">
        <dataProvider>
            <ArrayCollection>
                <String>1. The</String>
                <String>2. Quick</String>
                <String>3. Brown</String>
                <String includeIn="one">4. Fox</String>
                <String includeIn="two">5. Jumps</String>
                <String includeIn="one,two">6. Over</String>
                <String excludeFrom="one">7. The</String>
                <String excludeFrom="two">8. Lazy</String>
                <String excludeFrom="one,two">9. Dog</String>
            </ArrayCollection>
        </dataProvider>
    </FxList>

</FxApplication>

This entry is based on a beta version of the Flex Gumbo SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex Gumbo SDK.