Mike Chambers

code = joy

Using Pixel Bender Filters within Flex

with 3 comments

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 3.1.0.2710 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"
	applicationComplete="onApplicationComplete()">

	<mx:Script>
		<![CDATA[
			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:Script>

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

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.

Written by mikechambers

September 8th, 2008 at 1:26 pm

Posted in General

Tagged with ,

3 Responses to 'Using Pixel Bender Filters within Flex'

Subscribe to comments with RSS or TrackBack to 'Using Pixel Bender Filters within Flex'.

  1. [...] Using Pixel Bender Filters within Flex [...]

  2. Great read mike!

    But can we change shader filter values on the fly?
    I tried binding the amount.value to a HSlider but it doesn’t appear to work.

    Hyder Alamgir

    19 Apr 09 at 10:12 am

  3. [...] lets look at how you would normally apply a PxB shader.  The following example is taken from Mike Chamber’s blog: import flash.filters.*; import flash.utils.ByteArray;   //the file that contains the binary [...]

Leave a Reply