Advertisement
Guest User

Input.as

a guest
Oct 27th, 2010
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package input
  2. {
  3.     import flash.display.Stage;
  4.     import flash.events.KeyboardEvent;
  5.    
  6.     /**
  7.      * ...
  8.      * @author Yury Grigoryev
  9.      */
  10.     public class Input
  11.     {
  12.        
  13.         private static var _stage: Stage;
  14.        
  15.         private static var _keyDownStatus: Array;
  16.        
  17.         public function Input()
  18.         {
  19.            
  20.         }
  21.        
  22.         public static function init(stg: Stage):void
  23.         {
  24.             _stage = stg;
  25.            
  26.             _keyDownStatus = new Array(500);
  27.            
  28.             for each( var status: Boolean in _keyDownStatus ) {
  29.                 status = false;
  30.             }
  31.            
  32.             _stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownHandler );
  33.             _stage.addEventListener( KeyboardEvent.KEY_UP, keyUpHandler );
  34.         }
  35.        
  36.         public static function isKeyDown( key:int ): Boolean
  37.         {
  38.             return _keyDownStatus[ key ];
  39.         }
  40.        
  41.         public static function isKeyUp( key:int ): Boolean
  42.         {
  43.             return !_keyDownStatus[ key ];
  44.         }
  45.        
  46.         private static function keyDownHandler( event: KeyboardEvent ):void
  47.         {
  48.             _keyDownStatus[ event.keyCode ] = true;
  49.         }
  50.        
  51.         private static function keyUpHandler( event: KeyboardEvent ):void
  52.         {
  53.             _keyDownStatus[ event.keyCode ] = false;
  54.         }
  55.        
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement