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

Chapter 38 Example 1

Get Adobe Flash player
by actionscriptbible 09 Feb 2010
/**
 * Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/jkhp
 */

package {
  import flash.display.*;
  import flash.events.*;
  import flash.filters.*;
  import flash.media.*;
  import flash.net.*;
  import flash.utils.ByteArray;
  
  public class ch38ex1 extends Sprite {
    protected var camVideo:Video;
    protected var shader:Shader;
    protected var shaderFilter:ShaderFilter;
    public function ch38ex1() {
      camVideo = new Video(stage.stageWidth, stage.stageHeight);
      camVideo.attachCamera(Camera.getCamera());
      addChild(camVideo);
      
      var PBJURL:String = "http://actionscriptbible.com/files/circle2.pbj";
      var loader:URLLoader = new URLLoader(new URLRequest(PBJURL));
      loader.dataFormat = URLLoaderDataFormat.BINARY;
      loader.addEventListener(Event.COMPLETE, onBytecodeLoaded);
    }
    protected function onBytecodeLoaded(event:Event):void {
      var loader:URLLoader = URLLoader(event.target);
      loader.removeEventListener(Event.COMPLETE, onBytecodeLoaded);
      shader = new Shader(ByteArray(loader.data));
      shaderFilter = new ShaderFilter(shader);
      stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
      stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel)
    }
    protected function onEnterFrame(event:Event):void {
      shader.data.circleCenter.value = [stage.mouseX, stage.mouseY];
      camVideo.filters = [shaderFilter]; //update the filter
    }
    protected function onMouseWheel(event:MouseEvent):void {
      shader.data.circleRadius.value[0] += 3 * event.delta;
    }
  }
}