In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Pixel Bender Test 2

Pixel Bender Test2
// forked from northprint's Pixel Bender Test
// write as3 code here..
//Pixel Bender Test2
package {
    import flash.display.*;
    import flash.events.*;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLLoaderDataFormat;
    import flash.system.Security;
    import flash.filters.ShaderFilter;
    import flash.system.LoaderContext;

    [SWF(backgroundColor="#ffffff")]

    public class PixelBenderTest extends MovieClip{  

        private var _pbloader:URLLoader;
        private var _imgloader:Loader;
        private var _testShader:Shader;
        private var _filter:ShaderFilter;
        private var _bmp:Bitmap;
        private var _round:int = 250;

        public function PixelBenderTest(){
            Security.loadPolicyFile("http://narayama.heteml.jp/crossdomain.xml");
            _pbloader = new URLLoader();
            _pbloader.dataFormat = URLLoaderDataFormat.BINARY;
            _pbloader.addEventListener(Event.COMPLETE,PbLoadHandler);
            _pbloader.load(new URLRequest("http://narayama.heteml.jp/test/pixelbender/TestEffect.pbj"));
        }
        private function PbLoadHandler(e:Event):void{
            _imgloader = new Loader();
            _imgloader.contentLoaderInfo.addEventListener(Event.COMPLETE,ImgLoadHandler);
            _imgloader.load(new URLRequest("http://narayama.heteml.jp/test/pixelbender/rahsala.jpg"), new LoaderContext(true));
        }
        private function ImgLoadHandler(e:Event):void{
            var loaderInfo:LoaderInfo = LoaderInfo(e.currentTarget);
            var loader:Loader = loaderInfo.loader;
            var bmd:BitmapData = new BitmapData(loader.width, loader.height, true);
            bmd.draw(loader);

            _bmp = new Bitmap(bmd);
            _bmp.x = (stage.stageWidth/2) - (loader.width/2);
            _bmp.y = (stage.stageHeight/2) - (loader.height/2);

            _testShader = new Shader(_pbloader.data);
            _testShader.data.amount.value = [0.5];
            _testShader.data.color.value = [0,0,0];
            _testShader.data.center.value = [stage.stageWidth/2,stage.stageHeight/2];

            _filter = new ShaderFilter(_testShader);

            _bmp.filters = [_filter];
            addChild(_bmp);

            addEventListener(Event.ENTER_FRAME,EnterframeHandler);
        }
        private function EnterframeHandler(e:Event):void{
            _round-=5;
            if (_round<0){
                _round = 250;
                _testShader.data.color.value = [Math.random(),Math.random(),Math.random()];
            }
            _testShader.data.radius.value = [_round];
            _bmp.filters = [_filter];
        }
    }
}