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 35 Example 2

better result with a sharpen filter
-YopSolo-
/**
 * Copyright YopSolo ( http://wonderfl.net/user/YopSolo )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8oM0
 */

/* 
better result with a sharpen filter
-YopSolo-
*/

package {
  import flash.display.*;
  import flash.events.Event;
  import flash.geom.*;
  import flash.net.URLRequest;
  import flash.system.LoaderContext;
  import flash.filters.ConvolutionFilter
  
  [SWF(frameRate="10")]
  public class ch35ex2 extends Sprite {
    protected const SIZE:Rectangle = new Rectangle(0, 0, 48, 48);
    protected const SCALE:int = 4;
    protected var TOTALFRAMES:int;
    protected var bmp1:BitmapData; //on the left, no smoothing
    protected var bmp2:BitmapData; //on the right, smoothing
    protected var filmstrip:BitmapData;
    protected var frame:int = 0;
	
    private var sharpen:Array = [0, -1, 0, 
                                -1, 5, -1, 
                                 0, -1, 0]; 
     
    private var convolution:ConvolutionFilter = new ConvolutionFilter(); 
	
    public function ch35ex2() {
		
      var loader:Loader = new Loader();
      //Animation by Derek Yu - www.derekyu.com - used with permission
      loader.load(
        new URLRequest("http://actionscriptbible.com/files/monkey.png"),
        new LoaderContext(true));
      loader.contentLoaderInfo.addEventListener(Event.COMPLETE, LoadIsComplete);

		convolution.matrixX = 3; 
		convolution.matrixY = 3; 
		convolution.matrix = sharpen; 
		convolution.divisor = 1; 	

      bmp1 = new BitmapData(SIZE.width * SCALE, SIZE.height * SCALE);
      bmp2 = bmp1.clone();
      var bitmap:Bitmap = new Bitmap(bmp1);
      addChild(bitmap);
      bitmap = new Bitmap(bmp2);
      addChild(bitmap);
      bitmap.x = bmp1.width + 10;
    }
    protected function LoadIsComplete(event:Event):void {
      filmstrip = Bitmap(LoaderInfo(event.target).content).bitmapData;
      TOTALFRAMES = filmstrip.width / SIZE.width;
      addEventListener(Event.ENTER_FRAME, onEnterFrame);
    }
    protected function onEnterFrame(event:Event):void {
      frame = ++frame % TOTALFRAMES;
      //clear the bitmaps
      bmp1.fillRect(bmp1.rect, 0);
      bmp2.fillRect(bmp2.rect, 0);
      //shift the filmstrip left to put the correct frame in place; scale up
      var transform:Matrix = new Matrix();
      transform.translate(-frame * SIZE.width, 0);
      transform.scale(SCALE, SCALE);
      //omit sourceRect, let bitmap's own size clip the output
      bmp1.draw(filmstrip, transform, null, null, null, false);
      bmp2.draw(filmstrip, transform, null, null, null, true);
  	  bmp2.applyFilter( bmp2, bmp2.rect, new Point, convolution );
    }
  }
}