flash on 2012-5-24

by aina
♥0 | Line 48 | Modified 2012-05-24 14:47:36 | MIT License
play

ActionScript3 source code

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

package
{
    import flash.display.Sprite;
    import flash.events.KeyboardEvent;
    import flash.events.Event;
    import flash.ui.Keyboard;
    
    
    

    public class Main extends Sprite
    {
        
        private static const VK_LEFT:int = 37;
        private static const VK_UP:int = 38;
        private static const VK_RIGHT:int = 39;
        private static const VK_DOWN:int = 40;
        private static const VK_SPC:int = 32;
        
       
        var pos_x:Number;
        var pos_y:Number;

        public function Main()
        {
       
            this.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);

            pos_x = 200;
            pos_y = 150;

            Draw();
        }
        
       

        
    
        

               private function onKeyDown(e:KeyboardEvent):void
        {
            switch ( e.keyCode ) {
                case Keyboard.LEFT:
                    pos_x -= 1;
                    break;
                case Keyboard.RIGHT:
                    pos_x += 1;
                    break;
                case Keyboard.UP:
                    pos_y -= 1;
                    break;
                case Keyboard.DOWN:
                    pos_y += 1;
                    break;
            }

            Draw();
        }

        private function Draw():void
       {
            this.graphics.clear();
            this.graphics.lineStyle(3, 0x0000FF);
            this.graphics.drawCircle(pos_x,pos_y,20);
        }
    }
}