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

Blitting

Get Adobe Flash player
by Lorenz82 24 Sep 2010
    Embed
/**
 * Copyright Lorenz82 ( http://wonderfl.net/user/Lorenz82 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/cPSS
 */

package 
{    
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.utils.ByteArray;
    import flash.display.Loader;
    import mx.utils.Base64Decoder;
 
    // Here we declare the properties of our SWF.
    [SWF(width="100", height="100", frameRate="20", backgroundColor="0x330066", quality="high", scale="noscale")] 
    public class Main extends Sprite 
    {     
        
        private var PlaneBmp:Bitmap = new Bitmap();    //Crate a new Bitmap from it.
        private var FinalPlaneBmp:Bitmap = new Bitmap(); //Create an empty Bitmap.
 
        private var frameNumber:int; //Here we store the current frame number for blitting.
        private var point: Point = new Point(0, 0); //Anchor point, is usually 0,0.
        private var rect:Rectangle = new Rectangle(0, 0, 32, 32); //The rectangle that cut the section of the image that we need.
 
        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
 
        private function init(e:Event = null):void 
        {
            var loader:Loader = new Loader();
            loader.loadBytes(uncompress("iVBORw0KGgoAAAANSUhEUgAAAGAAAAAgCAYAAADtwH1UAAACKklEQVR42u2aC46EIAyGuZN36p24E3diLcq7ZQQRk60mzTjZod8PLe9V6sazbWDR1EuPaP4BV6etFyGW76O+gcptUTas4Btj7Ex+y99QpUHHz/T9qWBI56sSDuZ410ZHAaYW8fFnd32AUwAQAuB8f2Yoks6vJ58MOncy+j0G9/Nvj8ML639BhAoiIlwtWwmI4XNZk8ETEbMy71eZHv7sHjDKn58BLwoQwW+Ow1Avw9BWZN8If3oAXuZHATgJGXivAf47n8rcbE1cCKBWAXey3xLdupfP+ZmyJ7jIV7MaoNyQuHVwuhQjRIxWHsvN4s8KwAj/VuNbG4WX5x+sgEIE+uhtAM9Oy47wKT+jCThc/9Hge+Hc4ZPfEZICkvMQ72c0ALP43UnwYv2V204DA81nfWfc36Md/j7+hbMOClhaiLAXemZI8/epGGKcFM0nHeD37fw0ienoCLR25oX7k8JgqQ+iAh+fgu8F9e5Q710rGMIKAQjWxjo7ROQCWB9lFgnn5wE4JxW9R82oaPi9nHAQurOd5QJ++Gg1gEB+FQBcWmG0ssIA1ZKrJYDzcaUBpPGLnV3ehXD8yrpf0QVpAW0f1FJNMp/cZFyyDcIYOFqe2+RI4/OX0JkVlxDAbFLCb2sf3ZfgQvn9Z+ELz+Sl89vdddX/BQnmK27Xt7oBpPLDhYSb5f3SzKy/EJHMV1wX/PjrHgpuP/7Dj8bzj8Ti2Xn+PFZrhsPpWlX/O/w/R1CVKxNCtVUAAAAASUVORK5CYII="));
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
            function loadComplete(e:Event){
                var bmp:BitmapData=new BitmapData(loader.width,loader.height,true,0x0);
                bmp.draw(loader);
                PlaneBmp=new Bitmap(bmp);
                addEventListener(Event.ENTER_FRAME, update);
            }
            removeEventListener(Event.ADDED_TO_STAGE, init);
             
            addChild(FinalPlaneBmp); //Let's add the empty Bitmap on the stage.
            FinalPlaneBmp.smoothing = true;
            FinalPlaneBmp.bitmapData=new BitmapData(32, 32); //Fill it's bitmapData with an image 32x32.
            FinalPlaneBmp.x = 50;
            FinalPlaneBmp.y = 50;            
        }
 
        private function update(e:Event):void {
            frameNumber++;
            if (frameNumber >= 3) frameNumber = 0;
            rect.x = 32 * frameNumber; //Shift the rectangle position of 32 every frame, for 3 frames in loop.
            FinalPlaneBmp.bitmapData.copyPixels(PlaneBmp.bitmapData, rect, point); //Copy the images that is under the rectangle at that position of the PlaneBmp and copy it in the FinalPlaneBMP.
            FinalPlaneBmp.rotation++;
        }
        
        function uncompress(str:String):ByteArray {
            var dec:Base64Decoder = new Base64Decoder();
            dec.decode(str);
            var newByteArr:ByteArray=dec.toByteArray();        
            return newByteArr;
        }     
    }    
}