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

test

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

package {
    import flash.events.*;
    import flash.display.*;
    import org.si.cml.*;
    import org.si.cml.extensions.*;
    import org.si.b3.*;
    import net.hires.debug.Stats;

    [SWF(frameRate="60")]
    public class CMLObjectSample extends Sprite {
        public var stageCML:String = "py-160[px$??*100n{{[rw]}vy$?*10+2i40v~bm$i?(5)+2,45f5vd-10}w1]";
        function CMLObjectSample() {
            addEventListener(Event.ADDED_TO_STAGE, _setup);
        }

        private function _setup(e:Event):void {
            removeEventListener(Event.ADDED_TO_STAGE, _setup);
            mc = new CMLMovieClip(this, (465-W)/2, (465-H)/2, W, H, 0, true, _onFirstFrame);
        }

        private function _onFirstFrame():void {
            var cmlMaster:CMLMaster = new CMLMaster;
            cmlMaster.create(0, 0);
            cmlMaster.execute(new CMLSequence(stageCML));
            addEventListener("enterFrame", _onEnterFrame);
            addChild(new Stats);
        }

        private function _onEnterFrame(e:Event):void {
            // hit check between shots and enemies
            Actor.testf(shotFactory.evalIDNumber, enemyFactory.evalIDNumber);
            // hit check between bullets and player
            Actor.testf(playerFactory.evalIDNumber, bulletFactory.evalIDNumber);
            // render
            mc.screen.lock();
            mc.clearScreen();
            Actor.draw();
            mc.screen.unlock();
        }
    }
}

import flash.display.*;
import org.si.cml.*;
import org.si.cml.extensions.*;
import org.si.b3.*;
import org.si.b3.modules.*;

const W:int = 240;
const H:int = 320;
var mc:CMLMovieClip;
var enemyFactory:ActorFactory;
var bulletFactory:ActorFactory;
var playerFactory:ActorFactory;
var shotFactory:ActorFactory;
var player:Player;
var frameCount:int = 0;

class CMLMaster extends CMLObject {
    public function CMLMaster():void {
        enemyFactory = new ActorFactory(Enemy);
        bulletFactory = new ActorFactory(Bullet);
        playerFactory = new ActorFactory(Player);
        shotFactory = new ActorFactory(Shot);
        player = playerFactory.newInstance();
        player.create(0, 100);
        player.setAsDefaultTarget();
        super();
    }

    override public function onNewObject(args:Array):CMLObject {  
        return enemyFactory.newInstance();
    }
}

class Enemy extends Actor {
    public function Enemy() { size = 4; super(); }

    override public function onFireObject(args:Array):CMLObject {
        return bulletFactory.newInstance();
    }

    override public function onDraw():void {
        mc.fillRect(0xff4040, x-4, y-4, 9, 9);
    }

    override public function onHit(act:Actor):void {
        destroy(1);
    }
}

class Bullet extends Actor {
    public function Bullet() { size = 2; super(); }

    override public function onDraw():void { 
        mc.fillRect(0xff8080, x-2, y-2, 5, 5); 
    }
}

class Player extends Actor {
    public var ignoreHit:int = 60;

    public function Player() { size = 4; super(); }

    override public function onDraw():void {
        if(!(ignoreHit & 1)) mc.fillRect(0x4040ff, x-4, y-4, 9, 9);
    }

    override public function onUpdate():void {
        x += mc.control.x*5;
        y += mc.control.y*5;
        if(x > (W>>1)) x = W>>1;
        if(y > (H>>1)) y = H>>1;
        if(x < (-W>>1)) x = -W>>1;
        if(y < (-H>>1)) y = -H>>1;
        if(mc.control.isPressed(CMLMovieClipControl.KEY_BUTTON0)) {
            if(mc.control.getPressedFrame(CMLMovieClipControl.KEY_BUTTON0) & 1) {
                var shot:Shot = shotFactory.newInstance();
                shot.create(x, y);
            }
        }
        if(ignoreHit) ignoreHit--;
    }

    override public function onHit(act:Actor):void {
        ignoreHit = 60;
    }
}

class Shot extends Actor {
    public function Shot() { size = 3; super(); }

    override public function onDraw():void {
        mc.fillRect(0x8080ff, x-1, y-2, 3, 5);
    }

    override public function onUpdate():void {
        y -= 10;
        super.onUpdate(); // for isEscaped test - without this we leak resources
    }
}