Guest User

Input.as

a guest
Oct 27th, 2010
204
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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×