Some favorite site feeds aggregated locally: iPhone Development RSS   Adobe Labs RSS   Macrumors RSS

Friday, October 24, 2008

Linking to SWCs in Flash CS4. Using a customFilters.swc

Friday, October 24, 2008   

With Flash CS4, you can now link to external SWC files and use the code within to do your bidding in an application.

An example would be to bundle a bunch of Pixel Bender filters into a distributable SWC and then you can link to it using Flash CS4 (or Flex for that matter), and ring up some filter madness.



As you can see in the screenshot, there are 4 Pixel Bender filters available for use within a single SWC file. Less than around 8k for the SWC.

You'll need to create a FlexLibrary Project to get things rolling, but once you've done that, you'll have sharable bits for your team.

package
{

import flash.display.Shader;
import flash.filters.ShaderFilter;
import flash.utils.ByteArray;

public class ScanlineFilter extends ShaderFilter
{
[Embed("scanline.pbj", mimeType="application/octet-stream")]
private var Filter:Class;
private var _shader:Shader;
private var val:Number = 50;

public function ScanlineFilter()
{
_shader = new Shader( new Filter() as ByteArray );
super( _shader );
}

public function get value():Number
{
return _shader.data.amount.value[0];
}

public function set value( value:Number ):void
{
_shader.data.amount.value = [value];
}
}
}
To get things rolling in Flash CS4, what you'll need to do is link to the SWC using the new library path in the Actionscript 3.0 setup for the document. Here I am pointing to my Flexbuilder workspace.



When you've linked the SWC to your Flash document, the classes (filters) that are contained within it will be available for import and use.

Because you can't really inspect the classes themselves to know what kind of values they take, documentation is pretty crucial when you plan on distributing your own.

Now, let's import the classes from the SWC file and you'll see that they are easy to use from that point on.

import ScanlineFilter;
import HexFilter;
import SmudgeFilter;
import SquarePatternFilter;

Tareq Aljaber posted a similar thing yesterday in regards to Flex webservices and the same basic technique for using the new Library Path in Flash CS4.

Linking to SWC files in Flash CS4 is certainly a welcome thing, as is support for metdata. It's opened up so many more possibilities.
 
 Return to the main page
Comments:

There are currently 0 Comments:

 Leave a comment