Using the new filter effects in Flex Gumbo

by Peter deHaan on August 14, 2008

in BlurFilter, Filters, beta

The following example shows how you can use the new Flex Gumbo filter effects from the flex.filters.* package. These new filters allow you to modify the filter’s properties at runtime without needing to recreate and reapply the filter to the display 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/08/14/using-the-new-filter-effects-in-flex-gumbo/ -->
<Application name="Gumbo_Filters_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        xmlns:mx="library:adobe/flex/halo">
    <layout>
        <BasicLayout />
    </layout>

    <mx:Form>
        <mx:FormItem label="blurX:">
            <mx:HSlider id="blurXSlider"
                    minimum="0"
                    maximum="10"
                    value="4"
                    snapInterval="1"
                    tickInterval="1"
                    liveDragging="true" />
        </mx:FormItem>
        <mx:FormItem label="blurY:">
            <mx:HSlider id="blurYSlider"
                    minimum="0"
                    maximum="10"
                    value="4"
                    snapInterval="1"
                    tickInterval="1"
                    liveDragging="true" />
        </mx:FormItem>
        <mx:FormItem label="quality:">
            <mx:HSlider id="qualitySlider"
                    minimum="0"
                    maximum="10"
                    value="1"
                    snapInterval="1"
                    tickInterval="1"
                    liveDragging="true" />
        </mx:FormItem>
    </mx:Form>

    <BitmapGraphic id="img"
            source="@Embed('flex_logo.jpg')"
            horizontalCenter="0"
            verticalCenter="0">
        <filters>
            <BlurFilter id="blurFilter"
                    blurX="{blurXSlider.value}"
                    blurY="{blurYSlider.value}"
                    quality="{qualitySlider.value}" />
        </filters>
    </BitmapGraphic>

</Application>

View source is enabled in the following example.

You can also set the Gumbo BlurFilter filter’s blurX, blurY, and quality properties using ActionScript, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/08/14/using-the-new-filter-effects-in-flex-gumbo/ -->
<Application name="Gumbo_Filters_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        xmlns:mx="library:adobe/flex/halo">
    <layout>
        <BasicLayout />
    </layout>

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

            private function blurXSlider_change(evt:SliderEvent):void {
                blurFilter.blurX = evt.value;
            }

            private function blurYSlider_change(evt:SliderEvent):void {
                blurFilter.blurY = evt.value;
            }

            private function qualitySlider_change(evt:SliderEvent):void {
                blurFilter.quality = evt.value;
            }
        ]]>
    </Script>

    <mx:Form>
        <mx:FormItem label="blurX:">
            <mx:HSlider id="blurXSlider"
                    minimum="0"
                    maximum="10"
                    value="4"
                    snapInterval="1"
                    tickInterval="1"
                    liveDragging="true"
                    change="blurXSlider_change(event);" />
        </mx:FormItem>
        <mx:FormItem label="blurY:">
            <mx:HSlider id="blurYSlider"
                    minimum="0"
                    maximum="10"
                    value="4"
                    snapInterval="1"
                    tickInterval="1"
                    liveDragging="true"
                    change="blurYSlider_change(event);" />
        </mx:FormItem>
        <mx:FormItem label="quality:">
            <mx:HSlider id="qualitySlider"
                    minimum="0"
                    maximum="10"
                    value="1"
                    snapInterval="1"
                    tickInterval="1"
                    liveDragging="true"
                    change="qualitySlider_change(event);" />
        </mx:FormItem>
    </mx:Form>

    <BitmapGraphic id="img"
            source="@Embed('flex_logo.jpg')"
            horizontalCenter="0"
            verticalCenter="0">
        <filters>
            <BlurFilter id="blurFilter" />
        </filters>
    </BitmapGraphic>

</Application>

For more information, see http://livedocs.adobe.com/flex/gumbo/langref/.

{ 4 comments… read them below or add one }

1 Jens Wegar October 5, 2008 at 5:42 am

I’m getting the following compile error when I try to compile this example:

Initializer for ‘layout’: values of type flex.layout.LayoutBase cannot be represented in text.

Any idea why this would happen, other than it has something to do with the layout attribute in the Application tag? If I remove the layout-attribute, then the example compiles right away. This has actually happened with all Gumbo examples that I’ve tried so far that use the layout atrribute… =/

Reply

2 peterd October 5, 2008 at 11:09 am

Jens Wegar,

In more recent Flex Gumbo SDK builds the layout format was changed slightly. Instead of this code:

<Application name="Gumbo_Filters_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        xmlns:mx="library:adobe/flex/halo"
        layout="flex.layout.BasicLayout">

You set the layout property like this:

<Application name="Gumbo_Filters_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        xmlns:mx="library:adobe/flex/halo">
    <layout>
        <BasicLayout />
    </layout>

Peter

Reply

3 Jens Wegar October 5, 2008 at 12:22 pm

Great! It worked, thanks!

-Jens

Reply

4 peterd October 5, 2008 at 12:30 pm

Sorry, I should have updated the post. One of the reasons I try and avoid too many posts on alpha/beta topics, the posts tend to need a bit more “babysitting”.

Happy Flexing!
Peter

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: