home *** CD-ROM | disk | FTP | other *** search
- class Library.Utils.KeysManager
- {
- var aKeys;
- var oEnterFrameListener;
- static var EVENT_KEY_DOWN = 1;
- static var EVENT_KEY_UP = 2;
- function KeysManager()
- {
- this.aKeys = new Array();
- mx.transitions.OnEnterFrameBeacon.init();
- this.oEnterFrameListener = new Object();
- this.oEnterFrameListener.onEnterFrame = Library.Utils.Delegate.create(this,this.doEnterFrame);
- MovieClip.addListener(this.oEnterFrameListener);
- }
- function setListenerForKey(__oListener, __nKeyCode)
- {
- var _loc2_ = false;
- for(var _loc6_ in this.aKeys)
- {
- if(this.aKeys[_loc6_].nCode == __nKeyCode)
- {
- this.aKeys[_loc6_].aListeners.push(__oListener);
- _loc2_ = true;
- }
- }
- if(!_loc2_)
- {
- var _loc3_ = new Object();
- _loc3_.bPressed = false;
- _loc3_.nCode = __nKeyCode;
- _loc3_.aListeners = new Array();
- _loc3_.aListeners.push(__oListener);
- this.aKeys.push(_loc3_);
- }
- }
- function doEnterFrame()
- {
- for(var _loc5_ in this.aKeys)
- {
- var _loc3_ = Key.isDown(this.aKeys[_loc5_].nCode);
- if(this.aKeys[_loc5_].bPressed != _loc3_)
- {
- this.aKeys[_loc5_].bPressed = _loc3_;
- for(var _loc4_ in this.aKeys[_loc5_].aListeners)
- {
- var _loc2_ = undefined;
- if(_loc3_)
- {
- _loc2_ = Library.Utils.KeysManager.EVENT_KEY_DOWN;
- }
- else
- {
- _loc2_ = Library.Utils.KeysManager.EVENT_KEY_UP;
- }
- this.aKeys[_loc5_].aListeners[_loc4_].onKeyManagerEvent(_loc2_,this.aKeys[_loc5_].nCode);
- }
- }
- }
- }
- function isKeyDown(__nKeyCode)
- {
- return Key.isDown(__nKeyCode);
- }
- function doDestroy()
- {
- for(var _loc3_ in this.aKeys)
- {
- for(var _loc2_ in this.aKeys[_loc3_].aListeners)
- {
- delete this.aKeys[_loc3_].aListeners[_loc2_];
- }
- this.aKeys[_loc3_].aListeners = new Array();
- delete this.aKeys[_loc3_].aListeners;
- }
- this.aKeys = new Array();
- delete this.aKeys;
- MovieClip.removeListener(this);
- }
- }
-