topical media & game development
#graphic-flex-image-effects-05-Flex-HorizontalLinesTest.ax
#graphic-flex-image-effects-05-Flex-HorizontalLinesTest.ax
[swf]
[flash]
flex
package {
import flash.display.Shader;
import flash.filters.ShaderFilter;
import flash.events.Event;
[SWF(width=400, height=500, backgroundColor=0x000000)]
Demonstrates use of a custom shader as a bitmap filter.
public class @ax-graphic-flex-image-effects-05-Flex-HorizontalLinesTest extends graphic_flex_image_effects_05_Flex_AbstractImageLoader {
private var _shaderProxy:graphic_flex_image_effects_05_Flex_ShaderProxy;
Constructor. Passes path of image to load to super class.
public function @ax-graphic-flex-image-effects-05-Flex-HorizontalLinesTest() {
super("graphic-flex-image-effects-05-assets-cadillac.jpg");
}
Method that is called once image loads in super class.
This sets up loading of shader, or applies shader if bytes have been embedded.
override protected function runPostImageLoad():void {
_shaderProxy = new graphic_flex_image_effects_05_Flex_ShaderProxy("graphic-flex-image-effects-05-assets-horizontalLines.pbj");
if (_shaderProxy.shader == null) {
_shaderProxy.addEventListener(Event.COMPLETE, onShaderLoaded);
} else {
applyShader();
}
}
Sets properties on shader and applies it to the loaded image.
private function applyShader():void {
_shaderProxy.foregroundColor = [0.68, 0.7, 0.75, 1.0];
_shaderProxy.backgroundColor = [0.1, 0.25, 0.3, 1.0];
_shaderProxy.levelsThreshold = 0.25;
var shader:Shader = _shaderProxy.shader;
var filter:ShaderFilter = new ShaderFilter(shader);
_loadedBitmap.filters = [filter];
addChild(_loadedBitmap);
}
Handler for when the shader completes loading. Calls applyShader().
parameter: event Event dispatched by ShaderProxy.
private function onShaderLoaded(event:Event):void {
applyShader();
}
}
}
(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.