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

seeyourself5secsbefore

see yourself before 5 seconds.
@author rich850@gmail.com
Get Adobe Flash player
by rch850 11 Feb 2009
    Embed
package {
    import flash.display.*;
    import flash.events.*;
    import flash.media.*;
    import flash.text.*;
    /**
     * see yourself before 5 seconds.
     * @author rich850@gmail.com
     */
    [SWF(frameRate=5)]
    public class LookBack extends Sprite {
        public function LookBack():void {
            camera = Camera.getCamera();
            camera.setMode(320, 240, 10);
            now = new Video(camera.width, camera.height);
            now.attachCamera(camera);

            frameIndex = 25;

            var bmd:BitmapData = new BitmapData(camera.width, camera.height);
            before = new Bitmap(bmd);
            before.width = stage.stageWidth;
            before.height = stage.stageHeight;
            addChild(before);

            var nowIcon:Sprite = new Sprite();
            nowIcon.graphics.beginFill(0x0000FF);
            nowIcon.graphics.drawCircle(0, 0, 5);
            nowIcon.x = stage.stageWidth - 50;
            nowIcon.y = 10;
            addChild(nowIcon);

            frameSprite = new Sprite();
            frameSprite.graphics.beginFill(0xFFFF00);
            frameSprite.graphics.drawCircle(0, 0, 5);
            frameSprite.x = 50 + frameIndex / 50.0 * (stage.stageWidth - 100);
            frameSprite.y = 10;
            addChild(frameSprite);

            frames = [];
            addEventListener(Event.ENTER_FRAME, function(e:Event):void {
                registerFrame();
            });
            stage.addEventListener(MouseEvent.MOUSE_WHEEL, function(e:MouseEvent):void {
                changeFrameIndex(e.delta);
                e.preventDefault();
            });

            tf = new TextField(); // prevent scrolling
            tf.width = stage.stageWidth;
            tf.height = stage.stageHeight;
            tf.text = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
            tf.mouseWheelEnabled = true;
            tf.multiline = true;
            addChild(tf);

        }
        private function registerFrame():void {
            var bmp:BitmapData = new BitmapData(camera.width, camera.height);
            bmp.draw(now);
            frames.push(bmp);
            if (frames.length > 50) {
                frames.shift();
            }
            var i:int = frames.length - (49 - frameIndex);
            if (0 <= i || i < frames.length) {
                before.bitmapData = frames[i];
            }
        }
        private function changeFrameIndex(delta:int):void {
            tf.scrollV = 5;
            frameIndex += delta / 3;
            if (frameIndex < 0) { frameIndex = 0; }
            else if (frameIndex >= 50) { frameIndex = 49; }
            frameSprite.x = 50 + frameIndex / 50.0 * (stage.stageWidth - 100);
        }

        private var tf:TextField;
        private var camera:Camera;
        private var now:Video;
        private var before:Bitmap;
        private var frames:Array;
        private var frameIndex:int;
        private var frameSprite:Sprite;
    }
}