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

PixelBender/ShaderFilter + Animation

Get Adobe Flash player
by bradsedito 27 Nov 2011
// forked from ton's MAX 照英
// forked from northprint's Pixel Bender Test
// write as3 code here..
//Pixel Bender Test
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{  
        
        public  var SW:Number = new Number( stage.stageWidth  );
        public  var SH:Number = new Number( stage.stageHeight );
        public  var mX:Number;
        public  var mY:Number;
        private var _pbloader:URLLoader;
        private var _imgloader:Loader;
        private var _twirlShader:Shader;
        private var _filter:ShaderFilter;
        private var _bmp:Bitmap;

        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/twirlFlash.pbj"));
            addEventListener(Event.ENTER_FRAME, loopRealTime);
        }
        public function loopRealTime( event:Event ):void
        {
            mX = stage.mouseX;
            mY = stage.mouseY;
        }

        private function PbLoadHandler(e:Event):void{
            _imgloader = new Loader();
            _imgloader.contentLoaderInfo.addEventListener(Event.COMPLETE,ImgLoadHandler);
            _imgloader.load(new URLRequest("http://assets.wonderfl.net/images/related_images/3/37/370a/370a6943334aec28ae4411b809246963901c5c8a"), 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);
            var dynamicNumber:uint;
            bmd.draw(loader);

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

            _twirlShader = new Shader(_pbloader.data);
            _twirlShader.data["radius"]["value"] = [100];
            _twirlShader.data["twist"]["value"] = [mX/100];
            //_twirlShader.data["radius"]["value"] = [100];
            //_twirlShader.data["twist"]["value"] = [5];

            _filter = new ShaderFilter(_twirlShader);

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

            addEventListener(Event.ENTER_FRAME,EnterframeHandler);
        }
        private function EnterframeHandler(e:Event):void{
            _twirlShader.data["center"]["value"] = [_bmp.mouseX,_bmp.mouseY];
            _bmp.filters = [_filter];
        }
    }
}