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

flash on 2011-5-19

Get Adobe Flash player
by kihon 19 May 2011
package
{
    import flash.display.BitmapData;
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;
    
    public class Main extends Sprite
    {
        private var animGroup:Array = [];
        private var urlList:Array = 
        [
            "http://assets.wonderfl.net/images/related_images/1/10/10ff/10ff2ef814a8dbd99501f431ffd1a3c607f14d76",
            "http://assets.wonderfl.net/images/related_images/b/ba/ba45/ba45c8b80f3fed27f7263ad3cfc7268cab175c3d",
            "http://assets.wonderfl.net/images/related_images/9/97/9718/971882e8e30d1c03c9cc99cda35e0ce18fc399ad",
            "http://assets.wonderfl.net/images/related_images/3/37/3727/37270a084a31e827f29d12e429d8f3109591d665"
        ];
        private var chips:Array = [];
        
        public function Main()
        {
            graphics.beginFill(0x0);
            graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
            graphics.endFill();
            
            var count:int = 0;
            for (var i:int = 0; i < urlList.length; i++)
            {
                var loader:Loader = new Loader();
                loader.name = i.toString();
                loader.contentLoaderInfo.addEventListener(Event.INIT, function(event:Event):void
                {
                    var loader:Loader = event.currentTarget.loader;
                    var bd:BitmapData = new BitmapData(loader.width, loader.height, true, 0x0);
                    bd.draw(loader);
                    chips[int(loader.name)] = bd;
                    if (++count >= urlList.length) initialize();
                });
                loader.load(new URLRequest(urlList[i]), new LoaderContext(true));
            }
        }
        
        private function initialize():void
        {
            AnimSprite.stage = stage;
            animGroup.push(addChild(new Fire(0, 0, chips[0])));
            
            var commands:Array = ["down", "left", "right", "up"];
            for (var i:int = 0; i < commands.length; i++)
            {
                var chara:Character = new Character(50 * i, 100, chips[1]);
                chara.play(commands[i]);
                animGroup.push(addChild(chara));
            }
            animGroup.push(addChild(new Dokuro(0, 200, chips[2])));
            animGroup.push(addChild(new Dokuro(0, 300, chips[3])));
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        private function onEnterFrame(event:Event):void 
        {
            for each (var anim:AnimSprite in animGroup)
            {
                anim.update();
            }
        }
    }
}

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.Stage;
import flash.geom.Point;
import flash.geom.Rectangle;
 
class AnimSprite extends Sprite
{
    public static var stage:Stage;
    public static const ZERO:Point = new Point();
    public var curAnim:Anim;
    public var animGroup:Array = [];
    public var finished:Boolean = false;
    public var time:Number = 0.0;
    public var chip:BitmapData;
    public var chipWidth:Number;
    public var chipHeight:Number;
    public var xLength:int;
    public var bitmap:Bitmap;

    public function AnimSprite(x:Number, y:Number, chip:BitmapData, width:Number, height:Number)
    {
        this.x = x;
        this.y = y;
        this.chip = chip;
        this.chipWidth = width;
        this.chipHeight = height;
        this.xLength = chip.width / width;

        var bd:BitmapData = new BitmapData(width, height, true, 0x0);
        addChild(bitmap = new Bitmap(bd));
    }

    public function addAnimation(name:String, frames:Array, delay:Number, looped:Boolean):void
    {
        animGroup.push(new Anim(name, frames, 0, delay, looped));
    }

    public function play(name:String):void
    {
        for each (var anim:Anim in animGroup)
        {
            if (anim.name == name)
            {
                curAnim = anim;
                finished = false;
                time = 0.0;
                break;
            }
        }
    }

    public function update():void
    {
        bitmap.bitmapData.fillRect(bitmap.bitmapData.rect, 0x0);
        var tx:int = curAnim.frames[curAnim.index] % xLength;
        var ty:int = curAnim.frames[curAnim.index] / xLength;
        bitmap.bitmapData.copyPixels(chip, new Rectangle(tx * chipWidth, ty * chipHeight, chipWidth, chipHeight), ZERO);

        if (curAnim && curAnim.delay > 0 && (curAnim.looped || !finished))
        {
            time += 1 / stage.frameRate;
            while (time > curAnim.delay)
            {
                time -= curAnim.delay;

                if (curAnim.index >= curAnim.frames.length - 1)
                {
                    finished = true;
                    if (curAnim.looped) curAnim.index = 0;
                }
                else curAnim.index++;
            }
        }
    }
}

class Anim
{
    public var frames:Array;
    public var index:int;
    public var delay:Number;
    public var name:String;
    public var looped:Boolean;
    
    public function Anim(name:String, frames:Array, index:int, delay:Number, looped:Boolean):void
    {
        this.name = name;
        this.frames = frames;
        this.index = index;
        this.delay = delay;
        this.looped = looped;
    }
}

class Fire extends AnimSprite
{
    public function Fire(x:Number, y:Number, bd:BitmapData)
    {
        super(x, y, bd, 48, 48);
        addAnimation("play", [0, 1, 2, 3, 4, 5, 6, 7], 1 / 10, true);
        play("play");
        scaleX = scaleY = 2.5;
    }
}

class Character extends AnimSprite
{
    public function Character(x:Number, y:Number, bd:BitmapData)
    {
        const DELAY:Number = 1 / 8;
        super(x, y, bd, 32, 32);
        addAnimation("down", [0, 1, 2], DELAY, true);
        addAnimation("left", [3, 4, 5], DELAY, true);
        addAnimation("right", [6, 7, 8], DELAY, true);
        addAnimation("up", [9, 10, 11], DELAY, true);
        scaleX = scaleY = 2;
    }
}

class Dokuro extends AnimSprite
{
    public function Dokuro(x:Number, y:Number, bd:BitmapData)
    {
        super(x, y, bd, 48, 48);
        addAnimation("play", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1 / 8, true);
        play("play");
        scaleX = scaleY = 2;
    }
}

class Ice extends AnimSprite
{
    public function Ice(x:Number, y:Number, bd:BitmapData)
    {
        super(x, y, bd, 48, 48);
        addAnimation("play", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 1 / 8, true);
        play("play");
        scaleX = scaleY = 2;
    }
}