topical media & game development

talk show tell print

#graphic-flex-image-effects-05-Flex-DesaturateWithEmbedTest.ax

#graphic-flex-image-effects-05-Flex-DesaturateWithEmbedTest.ax [swf] [flash] flex


  package {
  
          import flash.display.Bitmap;
          import flash.display.Shader;
          import flash.display.Sprite;
          import flash.filters.ShaderFilter;
          import flash.utils.ByteArray;
                  
          [SWF(width=500, height=500, backgroundColor=0x000000)]
  
          
Demonstrates how to embed shader bytecode directly in a SWF and apply the shader at runtime as a filter.

  
          public class @ax-graphic-flex-image-effects-05-Flex-DesaturateWithEmbedTest extends Sprite {
  
                  [Embed(source='graphic-flex-image-effects-05-Flex-source-desaturate.pbj', mimeType='application/octet-stream')]
                  private static const DesaturateKernel:Class;
  
                  [Embed(source='graphic-flex-image-effects-05-Flex-source-butterflies.jpg')]
                  private static const BitmapClass:Class;
  
                  
Constructor. Instantiates shader and applies it as a filter to an embedded image.

  
                  public function @ax-graphic-flex-image-effects-05-Flex-DesaturateWithEmbedTest() {
                          var bitmap:Bitmap = new BitmapClass() as Bitmap;
                          var byteArray:ByteArray = new DesaturateKernel() as ByteArray;
                          var shader:Shader = new Shader(byteArray);
                          var filter:ShaderFilter = new ShaderFilter(shader);
                          bitmap.filters = [filter];
                          addChild(bitmap);
                  }
  
          }
  
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.