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

forked from: Chapter 36 Example 11

/**
 * Copyright hacker_9p8x8mco ( http://wonderfl.net/user/hacker_9p8x8mco )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/btJw
 */

// forked from actionscriptbible's Chapter 36 Example 11
package {
  import flash.display.Sprite;
  import flash.events.MouseEvent;
  import flash.filters.ColorMatrixFilter;

  public class ch36ex11 extends Sprite {
    protected var img:TestImage;
    function ch36ex11() {
      img = new TestImage();
      addChild(img);
      addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
    }
    protected function onMouseMove(event:MouseEvent):void {
      //1 for no change, 0 for desaturate, >1 for high saturation
      //mouse at left for grayscale, right for 3x saturation boost
      var s:Number = stage.mouseX / stage.stageWidth * 3;
      var R:Number = (1 - s) * 0.3086;
      var G:Number = (1 - s) * 0.6094;
      var B:Number = (1 - s) * 0.0820; 
      var satMatrix:Array = [R+s,   G,   B, 0, 0,
                               R, G+s,   B, 0, 0,
                               R,   G, B+s, 0, 0,
                               0,   0,   0, 1, 0];
      img.filters = [new ColorMatrixFilter(satMatrix)];
    }
  }
}
import flash.display.Loader;
import flash.net.URLRequest;
import flash.system.LoaderContext;
class TestImage extends Loader {
  public function TestImage(scale:Number = 1, x:Number = 0, y:Number = 0) {
    //photo   (CC-BY) Roger Braunstein
    //source  http://www.flickr.com/photos/rogerimp/2940373537/
    var url:String = "http://actionscriptbible.com/files/heiwadoori.jpg";
    load(new URLRequest(url), new LoaderContext(true));
    scaleX = scaleY = scale;
    this.x = x; this.y = y;
  }
}