Setting a bitmap fill on a shape in Flex Gumbo

The following example shows how you can set a bitmap fill on an Flex Gumbo Ellipse object by setting the source property on the BitmapFill object.

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/2008/12/07/setting-a-bitmap-fill-on-a-shape-in-flex-gumbo/ -->
<Application name="BitmapFill_source_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <ApplicationControlBar dock="true">
        <Form styleName="plain">
            <FormItem label="width:">
                <HSlider id="widthSlider"
                        minimum="100"
                        maximum="300"
                        value="300"
                        snapInterval="1"
                        tickInterval="50"
                        liveDragging="true" />
            </FormItem>
            <FormItem label="height:">
                <HSlider id="heightSlider"
                        minimum="100"
                        maximum="300"
                        value="200"
                        snapInterval="1"
                        tickInterval="50"
                        liveDragging="true" />
            </FormItem>
        </Form>
    </ApplicationControlBar>

    <Graphic>
        <Ellipse id="ellipse"
                width="{widthSlider.value}"
                height="{heightSlider.value}">
            <fill>
                <BitmapFill id="bitmapFill"
                        source="@Embed('assets/fx_appicon-tn.gif')" />
            </fill>
        </Ellipse>
    </Graphic>

</Application>

View source is enabled in the following example.

You can also embed the asset using ActionScript and set the BitmapFill source using data binding, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/12/07/setting-a-bitmap-fill-on-a-shape-in-flex-gumbo/ -->
<Application name="BitmapFill_source_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <Script>
        <![CDATA[
            [Embed("assets/fx_appicon-tn.gif")]
            private const FlexIcon:Class;
        ]]>
    </Script>

    <ApplicationControlBar dock="true">
        <Form styleName="plain">
            <FormItem label="width:">
                <HSlider id="widthSlider"
                        minimum="100"
                        maximum="300"
                        value="300"
                        snapInterval="1"
                        tickInterval="50"
                        liveDragging="true" />
            </FormItem>
            <FormItem label="height:">
                <HSlider id="heightSlider"
                        minimum="100"
                        maximum="300"
                        value="200"
                        snapInterval="1"
                        tickInterval="50"
                        liveDragging="true" />
            </FormItem>
        </Form>
    </ApplicationControlBar>

    <Graphic>
        <Ellipse id="ellipse"
                width="{widthSlider.value}"
                height="{heightSlider.value}">
            <fill>
                <BitmapFill id="bitmapFill"
                        source="{FlexIcon}" />
            </fill>
        </Ellipse>
    </Graphic>

</Application>

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.