mike chambers | about

Using Pixel Bender Filters within Flex

Following up on my earlier post on how to embed Pixel Bender filters within a SWF, here is a super simple example that show how to use a Pixel Bender filter within a Flex application.

Compiled using the Flex SDK, and requires Flash Player 10.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

            import flash.filters.*;
            import flash.utils.ByteArray;

            //the file that contains the binary bytes of the PixelBender filter
            [Embed("testfilter.pbj", mimeType="application/octet-stream")]
            private var TestFilter:Class;

            private function onApplicationComplete():void
                //Pass the loaded filter to the Shader as a ByteArray
                var shader:Shader = new Shader(new TestFilter() as ByteArray);

                shader.data.amount.value = [100];
                var filter:ShaderFilter = new ShaderFilter(shader);

                //add the filter to the image
                im.filters = [filter];

    <mx:Image right="288" left="40" top="26" bottom="108" id="im" source="@Embed(source='image.jpg')"/>

You can see an example of the filter here.

You can find more information on Pixel Bender here.

You can download the filter from here.

twitter github flickr behance