Compiling Shader SWCs with ANT build-files

Cool AntIn 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

  2. package {
  3. import flash.display.Shader;
  4. import flash.utils.ByteArray;
  6. public class Shaders {
  8. [Embed("RippleTransition.pbj", mimeType="application/octet-stream")]
  9. private static var RippleTransitionData : Class;
  11. [Embed("Bloom.pbj", mimeType="application/octet-stream")]
  12. private static var BloomData : Class;
  14. [Embed("BlendModeSoftlight.pbj", mimeType="application/octet-stream")]
  15. private static var SoftLightBlendModeData : Class;
  17. // Transitions
  18. public static var rippleTransition : Shader;
  20. //Lighting
  21. public static var bloom : Shader;
  23. //BlendModes
  24. public static var softLightBlendMode : Shader;
  26. protected static var inited : Boolean = init();
  28. private static function init() : Boolean {
  29. rippleTransition = new Shader(new RippleTransitionData() as ByteArray);
  31. bloom = new Shader(new BloomData() as ByteArray);
  33. softLightBlendMode = new Shader(new SoftLightBlendModeData() as ByteArray);
  35. return true;
  36. }
  37. }
  38. }

Download the handy ANT buildfiles here

If you are interested in writing your own ANT build files read up about this here