« Compiling Shader SWCs with ANT build-files»
- Published on › 25.02.09 | Filed under › Interesting, Source
In my talk I briefly introduced the concept of using Flex to compile to a SWC containing Shaders. If you've used Shaders it's rather annoying you have to load in an exported Shader .pbj file at runtime before you can use a Shader. I really like the idea of having my shaders in a SWC to get around this problem. But this is also useful as a means to distribute your Shaders especially for the Shaders I use often like custom blendModes and some filter effects.
I usually compile SWCs via an ANT buildfile in Eclipse and I will provide this handy script to you as open source code. I like using ANT because it makes it very easy for me to automate the task of creating SWCs then even carrying out other tasks like FTPing.
As well as compiling SWCs and SWFs using ANT I also often publish documentation using these build-files and as my FITC talk briefly covered Javadoc in regard to 'coding conventions' I will also include the source code for how to convert your Javadoc notation to HTML documentation using Flex with asdoc via an ANT build-file.
But before you use these ANT build-files it's important to mention you will need to setup up the appropriate .prefs file to match particular variables to your system.
Here is an example which demonstrates the .prefs file for the SWC ANT build-file
compc =/Applications/Flex SDK 4/bin/compc src =/classes outputFile =/swc/TheSWC.swc
Here is the code you may like to use as a reference to compiling your Shader files into a swc
package { import flash.display.Shader; import flash.utils.ByteArray; public class Shaders { [Embed("RippleTransition.pbj", mimeType="application/octet-stream")] private static var RippleTransitionData : Class; [Embed("Bloom.pbj", mimeType="application/octet-stream")] private static var BloomData : Class; [Embed("BlendModeSoftlight.pbj", mimeType="application/octet-stream")] private static var SoftLightBlendModeData : Class; // Transitions public static var rippleTransition : Shader; //Lighting public static var bloom : Shader; //BlendModes public static var softLightBlendMode : Shader; protected static var inited : Boolean = init(); private static function init() : Boolean { rippleTransition = new Shader(new RippleTransitionData() as ByteArray); bloom = new Shader(new BloomData() as ByteArray); softLightBlendMode = new Shader(new SoftLightBlendModeData() as ByteArray); return true; } } }
Download the handy ANT buildfiles here
If you are interested in writing your own ANT build files read up about this here


2 Comments