Setting a blend mode on an Ellipse in Flex Gumbo

The following example shows how you can set the blend mode of an Ellipse object by setting the blendMode property.

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/11/25/setting-a-blend-mode-on-an-ellipse-in-flex-gumbo/ -->
<FxApplication name="Ellipse_blendMode_test"
        xmlns="http://ns.adobe.com/mxml/2009">

    <Form>
        <FormItem label="blendMode:">
            <ComboBox id="comboBox">
                <dataProvider>
                    <String>{BlendMode.ADD}</String>
                    <String>{BlendMode.ALPHA}</String>
                    <String>{BlendMode.DARKEN}</String>
                    <String>{BlendMode.DIFFERENCE}</String>
                    <String>{BlendMode.ERASE}</String>
                    <String>{BlendMode.HARDLIGHT}</String>
                    <String>{BlendMode.INVERT}</String>
                    <String>{BlendMode.LAYER}</String>
                    <String>{BlendMode.LIGHTEN}</String>
                    <String>{BlendMode.MULTIPLY}</String>
                    <String>{BlendMode.NORMAL}</String>
                    <String>{BlendMode.OVERLAY}</String>
                    <String>{BlendMode.SCREEN}</String>
                    <String>{BlendMode.SHADER}</String>
                    <String>{BlendMode.SUBTRACT}</String>
                </dataProvider>
            </ComboBox>
        </FormItem>
    </Form>

    <Ellipse id="ellipse1"
            width="100"
            height="100"
            horizontalCenter="-25"
            verticalCenter="-25">
        <fill>
            <SolidColor color="red" />
        </fill>
    </Ellipse>

    <Ellipse id="ellipse2"
            width="100"
            height="100"
            horizontalCenter="25"
            verticalCenter="-25">
        <fill>
            <SolidColor color="blue" />
        </fill>
    </Ellipse>

    <Ellipse id="ellipse3"
            blendMode="{comboBox.selectedItem}"
            width="100"
            height="100"
            horizontalCenter="0"
            verticalCenter="25">
        <fill>
            <SolidColor color="green" />
        </fill>
    </Ellipse>

</FxApplication>

You can also set the blendMode property using ActionScript, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/11/25/setting-a-blend-mode-on-an-ellipse-in-flex-gumbo/ -->
<FxApplication name="Ellipse_blendMode_test"
        xmlns="http://ns.adobe.com/mxml/2009">

    <Script>
        <![CDATA[
            import mx.events.ListEvent;

            private function comboBox_change(evt:ListEvent):void {
                ellipse3.blendMode = comboBox.selectedItem.toString();
            }
        ]]>
    </Script>

    <Form>
        <FormItem label="blendMode:">
            <ComboBox id="comboBox"
                    change="comboBox_change(event);">
                <dataProvider>
                    <String>{BlendMode.ADD}</String>
                    <String>{BlendMode.ALPHA}</String>
                    <String>{BlendMode.DARKEN}</String>
                    <String>{BlendMode.DIFFERENCE}</String>
                    <String>{BlendMode.ERASE}</String>
                    <String>{BlendMode.HARDLIGHT}</String>
                    <String>{BlendMode.INVERT}</String>
                    <String>{BlendMode.LAYER}</String>
                    <String>{BlendMode.LIGHTEN}</String>
                    <String>{BlendMode.MULTIPLY}</String>
                    <String>{BlendMode.NORMAL}</String>
                    <String>{BlendMode.OVERLAY}</String>
                    <String>{BlendMode.SCREEN}</String>
                    <String>{BlendMode.SHADER}</String>
                    <String>{BlendMode.SUBTRACT}</String>
                </dataProvider>
            </ComboBox>
        </FormItem>
    </Form>

    <Ellipse id="ellipse1"
            width="100"
            height="100"
            horizontalCenter="-25"
            verticalCenter="-25">
        <fill>
            <SolidColor color="red" />
        </fill>
    </Ellipse>

    <Ellipse id="ellipse2"
            width="100"
            height="100"
            horizontalCenter="25"
            verticalCenter="-25">
        <fill>
            <SolidColor color="blue" />
        </fill>
    </Ellipse>

    <Ellipse id="ellipse3"
            width="100"
            height="100"
            horizontalCenter="0"
            verticalCenter="25">
        <fill>
            <SolidColor color="green" />
        </fill>
    </Ellipse>

</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.