package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.BlendMode; import flash.display.Shader; import flash.filters.ShaderFilter; import flash.events.Event; import flash.geom.Point; [SWF(width=1200, height=600, backgroundColor=0x000000)] /** * Demonstrates use of shader for new blend modes using a Color Burn shader with opacity settings. */ public class graphic_flex_image_effects_05_Flex_ColorBurnTest extends graphic_flex_image_effects_05_Flex_DualImageTest { private var _shaderProxy:graphic_flex_image_effects_05_Flex_ShaderProxy; /** * Method that is called once both images load in super class. * This sets up loading of shader, or applies shader if bytes have been embedded. */ override protected function operateOnImages():void { // update path if shader is kept in different directory _shaderProxy = new graphic_flex_image_effects_05_Flex_ShaderProxy("graphic-flex-image-effects-05-assets-colorBurn.pbj"); if (_shaderProxy.shader == null) { _shaderProxy.addEventListener(Event.COMPLETE, onShaderLoaded); } else { applyShader(); } } /** * Copies the two loaded bitmaps, stacks the copies and applies the blend mode shader. */ private function applyShader():void { var bitmap0:Bitmap = getChildAt(0) as Bitmap; var bitmap1:Bitmap = getChildAt(1) as Bitmap; // two new bitmaps showing the loaded data var bottomBitmap:Bitmap = new Bitmap(bitmap0.bitmapData); var topBitmap:Bitmap = new Bitmap(bitmap1.bitmapData); addChild(bottomBitmap); addChild(topBitmap); // places both new bitmaps at the right topBitmap.x = bottomBitmap.x = bitmap1.x + bitmap1.width; // sets the blend mode alpha and applies the shader _shaderProxy.percent = 0.6; topBitmap.blendShader = _shaderProxy.shader; } /** * Handler for when the shader completes loading. Calls applyShader(). * * @param event Event dispatched by ShaderProxy. */ private function onShaderLoaded(event:Event):void { applyShader(); } } }