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 2016-5-22

Get Adobe Flash player
by mutantleg 22 May 2016
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/Yanc
 */

package {
    import flash.ui.Keyboard;
    import flash.events.KeyboardEvent;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
  
          stage.addEventListener(KeyboardEvent.KEY_DOWN, onKdown);
          stage.addEventListener(KeyboardEvent.KEY_UP, onKup);
          stage.addEventListener(Event.ENTER_FRAME, onEnter);          
        }//ctor
        
        public var vecKey:Vector.<Boolean> = new Vector.<Boolean>(512,false);
        public function onKdown(e:KeyboardEvent):void { vecKey[e.keyCode]=true; }
        public function onKup(e:KeyboardEvent):void { vecKey[e.keyCode]=false; }
        public function isKey(k:int):Boolean { return vecKey[k];  }
        
        public var cx:Number = 235;
        public var cy:Number = 235;
        public var vx:Number=0;
        public var vy:Number=0;
        
        public function isWall(ax:Number, ay:Number):Boolean
        {
           if (ay>400){ return true;}
           if (inRect(ax,ay, 300,0,32+64,256+64+64)){ return true; }
           if (inRect(ax,ay,100,0, 64,256)){ return true; }
           if (inRect(ax,ay,100,256+16, 64,256)){ return true; }
        
           return false;   
        }//iswall
 
        public function inRect(ax:Number,ay:Number,  rx:Number,ry:Number,rw:Number,rh:Number):Boolean
        { return (ax<rx||ay<ry||ax>rx+rw||ay>ry+rh)==false; }
        
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2, 0);
            
            
            var ms:Number; ms=6;
            vx=0;
            //vy=0;
            if (isKey(Keyboard.LEFT)) { vx-=ms; }
            if (isKey(Keyboard.RIGHT)) { vx+=ms; }
            if (isKey(Keyboard.UP)) { vy-=ms; }
            if (isKey(Keyboard.DOWN)) { vy+=ms; }
            
            graphics.drawCircle(cx,cy, 8);
            
            graphics.drawRect(0,400,465,40);
            graphics.drawRect(300,0,32+64,256+64+64);
            graphics.drawRect(100,0, 64,256);
            graphics.drawRect(100,256+16, 64,256);
            
            vy+=1; if(vy>4){vy=4;}
            if (vy<-4){vy=-4;}
            
            var h:Number;
            h = isKey(Keyboard.DOWN)?8:32;
            if (isWall(cx,cy-12)&&isWall(cx,cy+12)){h=8;}
            graphics.moveTo(cx,cy);
            graphics.lineTo(cx,cy+h);
            
           // if (isWall(cx,cy+17)==false) {cy+=4; }
            if (isWall(cx,cy+h+vy)&&vy>0){vy=0;}
            if (isWall(cx,cy-12)&&vy<0){vy=0;}
            if (isWall(cx+8,cy)&&vx>0){vx=0;}
            if (isWall(cx-8,cy)&&vx<0){vx=0;}
            
            var i:int;
            for(i=0;i<3;i+=1){ if (isWall(cx,cy-12)){break;} if (isWall(cx,cy+h)) {cy-=1; }}
            
            
            cx+=vx;cy+=vy;
            
        }//onenter
        
        
    }//classend
}