Chapter 37 Example 11
/**
* Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/kKw7
*/
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.filters.ColorMatrixFilter;
public class ch37ex11 extends Sprite {
protected var img:TestImage;
function ch37ex11() {
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;
}
}