home *** CD-ROM | disk | FTP | other *** search
/ Champak 48 / cdrom_image.iso / Games / breakawish.swf / scripts / __Packages / Library / Utils / KeysManager.as < prev    next >
Encoding:
Text File  |  2007-09-28  |  2.3 KB  |  80 lines

  1. class Library.Utils.KeysManager
  2. {
  3.    var aKeys;
  4.    var oEnterFrameListener;
  5.    static var EVENT_KEY_DOWN = 1;
  6.    static var EVENT_KEY_UP = 2;
  7.    function KeysManager()
  8.    {
  9.       this.aKeys = new Array();
  10.       mx.transitions.OnEnterFrameBeacon.init();
  11.       this.oEnterFrameListener = new Object();
  12.       this.oEnterFrameListener.onEnterFrame = Library.Utils.Delegate.create(this,this.doEnterFrame);
  13.       MovieClip.addListener(this.oEnterFrameListener);
  14.    }
  15.    function setListenerForKey(__oListener, __nKeyCode)
  16.    {
  17.       var _loc2_ = false;
  18.       for(var _loc6_ in this.aKeys)
  19.       {
  20.          if(this.aKeys[_loc6_].nCode == __nKeyCode)
  21.          {
  22.             this.aKeys[_loc6_].aListeners.push(__oListener);
  23.             _loc2_ = true;
  24.          }
  25.       }
  26.       if(!_loc2_)
  27.       {
  28.          var _loc3_ = new Object();
  29.          _loc3_.bPressed = false;
  30.          _loc3_.nCode = __nKeyCode;
  31.          _loc3_.aListeners = new Array();
  32.          _loc3_.aListeners.push(__oListener);
  33.          this.aKeys.push(_loc3_);
  34.       }
  35.    }
  36.    function doEnterFrame()
  37.    {
  38.       for(var _loc5_ in this.aKeys)
  39.       {
  40.          var _loc3_ = Key.isDown(this.aKeys[_loc5_].nCode);
  41.          if(this.aKeys[_loc5_].bPressed != _loc3_)
  42.          {
  43.             this.aKeys[_loc5_].bPressed = _loc3_;
  44.             for(var _loc4_ in this.aKeys[_loc5_].aListeners)
  45.             {
  46.                var _loc2_ = undefined;
  47.                if(_loc3_)
  48.                {
  49.                   _loc2_ = Library.Utils.KeysManager.EVENT_KEY_DOWN;
  50.                }
  51.                else
  52.                {
  53.                   _loc2_ = Library.Utils.KeysManager.EVENT_KEY_UP;
  54.                }
  55.                this.aKeys[_loc5_].aListeners[_loc4_].onKeyManagerEvent(_loc2_,this.aKeys[_loc5_].nCode);
  56.             }
  57.          }
  58.       }
  59.    }
  60.    function isKeyDown(__nKeyCode)
  61.    {
  62.       return Key.isDown(__nKeyCode);
  63.    }
  64.    function doDestroy()
  65.    {
  66.       for(var _loc3_ in this.aKeys)
  67.       {
  68.          for(var _loc2_ in this.aKeys[_loc3_].aListeners)
  69.          {
  70.             delete this.aKeys[_loc3_].aListeners[_loc2_];
  71.          }
  72.          this.aKeys[_loc3_].aListeners = new Array();
  73.          delete this.aKeys[_loc3_].aListeners;
  74.       }
  75.       this.aKeys = new Array();
  76.       delete this.aKeys;
  77.       MovieClip.removeListener(this);
  78.    }
  79. }
  80.