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″.
<?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:
<?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/.




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… =/
Jens Wegar,
In more recent Flex Gumbo SDK builds the
layoutformat 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
layoutproperty like this:<Application name="Gumbo_Filters_test" xmlns="http://ns.adobe.com/mxml/2009" xmlns:mx="library:adobe/flex/halo"> <layout> <BasicLayout /> </layout>Peter
Great! It worked, thanks!
-Jens
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