Advertisement
nutter666

KeyboardManager AS3

Jan 28th, 2013
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package {
  2.  
  3.     import flash.ui.Keyboard;
  4.     import flash.events.KeyboardEvent;
  5.     import flash.events.Event;
  6.  
  7.     public class KeyboardManager {
  8.  
  9.         var keyArray:Array = new Array();
  10.         var i:Number;
  11.        
  12.         public function KeyboardManager(stageClip) {
  13.             // constructor code
  14.         stageClip.addEventListener(KeyboardEvent.KEY_DOWN,kDown)   
  15.         stageClip.addEventListener(KeyboardEvent.KEY_UP,kUp)   
  16.            
  17.         for (i=0; i<222; i++) {
  18.             keyArray.push([i,false]);
  19.         }
  20.         }
  21.  
  22.         function kDown(event:KeyboardEvent) {
  23.             keyArray[event.keyCode][1]=true;
  24.         }
  25.        
  26.         function kUp(event:KeyboardEvent) {
  27.             keyArray[event.keyCode][1]=false;
  28.         }
  29.  
  30.         public function isKeyDown(key) {
  31.         return keyArray[key][1];
  32.         }
  33.  
  34.     }
  35.  
  36. }
  37.  
  38. /* designed to work like as2's key.isDown(x) function.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement