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 36 Example 3

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

package {
  import flash.display.*;
  import flash.events.Event;
  import flash.geom.*;
  import flash.net.URLRequest;
  import flash.system.LoaderContext;
  
  [SWF(frameRate="10")]
  public class ch36ex3 extends Sprite {
    protected const SIZE:Rectangle = new Rectangle(0, 0, 48, 48);
    protected var TOTALFRAMES:int;
    protected var bmp:BitmapData;
    protected var filmstrip:BitmapData;
    protected var frame:int = 0;
    protected var sourceRect:Rectangle = SIZE.clone();
    public function ch36ex3() {
      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, onLoad);
      
      bmp = new BitmapData(SIZE.width, SIZE.height);
      var bitmap:Bitmap = new Bitmap(bmp, PixelSnapping.ALWAYS, false);
      bitmap.scaleX = bitmap.scaleY = 4;
      addChild(bitmap);
    }
    protected function onLoad(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;
      sourceRect.x = frame * SIZE.width;
      bmp.fillRect(bmp.rect, 0);
      bmp.copyPixels(filmstrip, sourceRect, new Point(0,0));
    }
  }
}