home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
404 Jogos
/
CLJG.iso
/
Puzzle
/
HexiomConnect.swf
/
scripts
/
Input.as
< prev
next >
Wrap
Text File
|
2008-08-29
|
11KB
|
410 lines
package
{
import flash.display.Stage;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;
public class Input
{
public static const NO_KEYCODE:uint = 258;
private static var down:Array = new Array();
private static var released:Array = new Array();
private static var keyCount:uint = 0;
public static const UNDO_KEY:uint = keyCount++ * 2;
public static const CLEAR_SELECTION_KEY:uint = keyCount++ * 2;
public static const CHAT_KEY:uint = keyCount++ * 2;
public static const NEXT_CHARACTER_KEY:uint = keyCount++ * 2;
public static const DEFEND_KEY:uint = keyCount++ * 2;
public static const NUM_KEYS:uint = keyCount * 2;
public static const DOWN_KEY:uint = keyCount++ * 2;
public static const UP_KEY:uint = keyCount++ * 2;
public static const SELF_ABILITY_KEY:uint = keyCount++ * 2;
public static const TRANSPARENT_GUI_KEY:uint = keyCount++ * 2;
public static const LEFT_KEY:uint = keyCount++ * 2;
public static const CLOSEST_CHARACTER_KEY:uint = keyCount++ * 2;
public static const MOUSE_KEYCODE:uint = 257;
private static var keys:Array = new Array();
public static const RIGHT_KEY:uint = keyCount++ * 2;
public static const VIEW_FORTRESS_KEY:uint = keyCount++ * 2;
public function Input()
{
super();
}
public static function flush() : void
{
var _loc1_:int = 0;
while(_loc1_ < NUM_KEYS)
{
down[keys[_loc1_]] = false;
released[keys[_loc1_]] = true;
_loc1_++;
}
}
public static function newPress(param1:int) : Boolean
{
return down[keys[param1]] && released[keys[param1]] || down[keys[param1 + 1]] && released[keys[param1 + 1]];
}
public static function getSecondaryBindString(param1:uint) : String
{
return getCharString(keys[param1 + 1]);
}
public static function init(param1:Stage) : Boolean
{
defaults();
flush();
if(!param1)
{
return false;
}
param1.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
param1.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
param1.addEventListener(Event.MOUSE_LEAVE,mouseLeave);
param1.addEventListener(KeyboardEvent.KEY_DOWN,keyDown);
param1.addEventListener(KeyboardEvent.KEY_UP,keyUp);
return true;
}
public static function mouseLeave(param1:Event) : void
{
var _loc2_:int = 0;
while(_loc2_ < NUM_KEYS)
{
down[keys[_loc2_]] = false;
released[keys[_loc2_]] = true;
_loc2_++;
}
}
public static function getPrimaryBindString(param1:uint) : String
{
return getCharString(keys[param1]);
}
public static function mouseUp(param1:MouseEvent) : void
{
down[MOUSE_KEYCODE] = false;
released[MOUSE_KEYCODE] = true;
}
public static function keyDown(param1:KeyboardEvent) : void
{
var _loc2_:uint = param1.keyCode;
down[_loc2_] = true;
}
public static function setBind(param1:int, param2:Boolean, param3:uint) : void
{
if(param2)
{
keys[param1] = param3;
}
else
{
keys[param1 + 1] = param3;
}
}
public static function bindString(param1:uint) : String
{
var _loc2_:String = getPrimaryBindString(param1);
if(_loc2_ != "")
{
return _loc2_;
}
_loc2_ = getSecondaryBindString(param1);
if(_loc2_ != "")
{
return _loc2_;
}
return "No-Key-Set";
}
public static function update() : void
{
var _loc1_:int = 0;
while(_loc1_ < NUM_KEYS)
{
released[keys[_loc1_]] = !down[keys[_loc1_]];
_loc1_++;
}
}
public static function defaults() : void
{
var _loc1_:uint = 0;
while(_loc1_ < NUM_KEYS)
{
keys[_loc1_] = NO_KEYCODE;
_loc1_++;
}
keys[LEFT_KEY] = 65;
keys[LEFT_KEY + 1] = Keyboard.LEFT;
keys[RIGHT_KEY] = 68;
keys[RIGHT_KEY + 1] = Keyboard.RIGHT;
keys[UP_KEY] = 87;
keys[UP_KEY + 1] = Keyboard.UP;
keys[DOWN_KEY] = 83;
keys[DOWN_KEY + 1] = Keyboard.DOWN;
keys[UNDO_KEY] = 82;
keys[UNDO_KEY + 1] = Keyboard.BACKSPACE;
keys[CLEAR_SELECTION_KEY] = Keyboard.ESCAPE;
keys[NEXT_CHARACTER_KEY] = Keyboard.TAB;
keys[CLOSEST_CHARACTER_KEY] = 67;
keys[VIEW_FORTRESS_KEY] = 70;
keys[VIEW_FORTRESS_KEY + 1] = Keyboard.HOME;
keys[SELF_ABILITY_KEY] = 49;
keys[SELF_ABILITY_KEY + 1] = 96;
keys[DEFEND_KEY] = Keyboard.SPACE;
keys[DEFEND_KEY + 1] = Keyboard.END;
keys[CHAT_KEY] = Keyboard.ENTER;
keys[TRANSPARENT_GUI_KEY] = Keyboard.CONTROL;
}
public static function keyUp(param1:KeyboardEvent) : void
{
var _loc2_:uint = param1.keyCode;
down[_loc2_] = false;
released[_loc2_] = true;
}
public static function mouseDown(param1:MouseEvent) : void
{
down[MOUSE_KEYCODE] = true;
}
public static function isDown(param1:int) : Boolean
{
return down[keys[param1]] || down[keys[param1 + 1]];
}
public static function getCharString(param1:uint) : String
{
switch(param1)
{
case NO_KEYCODE:
return "";
case MOUSE_KEYCODE:
return "Mouse Button";
case 65:
return "A";
case 66:
return "B";
case 67:
return "C";
case 68:
return "D";
case 69:
return "E";
case 70:
return "F";
case 71:
return "G";
case 72:
return "H";
case 73:
return "I";
case 74:
return "J";
case 75:
return "K";
case 76:
return "L";
case 77:
return "M";
case 78:
return "N";
case 79:
return "O";
case 80:
return "P";
case 81:
return "Q";
case 82:
return "R";
case 83:
return "S";
case 84:
return "T";
case 85:
return "U";
case 86:
return "V";
case 87:
return "W";
case 88:
return "X";
case 89:
return "Y";
case 90:
return "Z";
case 27:
return "Esc";
case 112:
return "F1";
case 113:
return "F2";
case 114:
return "F3";
case 115:
return "F4";
case 116:
return "F5";
case 117:
return "F6";
case 118:
return "F7";
case 119:
return "F8";
case 120:
return "F9";
case 122:
return "F11";
case 123:
return "F12";
case 145:
return "Scroll Lock";
case 19:
return "Pause";
case 192:
return "`";
case 49:
return "1";
case 50:
return "2";
case 51:
return "3";
case 52:
return "4";
case 53:
return "5";
case 54:
return "6";
case 55:
return "7";
case 56:
return "8";
case 57:
return "9";
case 48:
return "0";
case 189:
return "-";
case 187:
return "=";
case 8:
return "Backspace";
case 9:
return "Tab";
case 20:
return "Caps Lock";
case 16:
return "Shift";
case 17:
return "Control";
case 32:
return "Space";
case 13:
return "Enter";
case 220:
return "\\";
case 37:
return "Left";
case 39:
return "Right";
case 38:
return "Up";
case 40:
return "Down";
case 45:
return "Insert";
case 46:
return "Del";
case 36:
return "Home";
case 35:
return "End";
case 33:
return "Page Up";
case 34:
return "Page Down";
case 144:
return "Num Lock";
case 96:
return "Numpad Ins";
case 97:
return "Numpad 1";
case 98:
return "Numpad 2";
case 99:
return "Numpad 3";
case 100:
return "Numpad 4";
case 101:
return "Numpad 5";
case 102:
return "Numpad 6";
case 103:
return "Numpad 7";
case 104:
return "Numpad 8";
case 105:
return "Numpad 9";
case 106:
return "Numpad *";
case 107:
return "Numpad +";
case 109:
return "Numpad -";
case 110:
return "Numpad Del";
case 111:
return "Numpad /";
case 219:
return "[";
case 221:
return "]";
case 186:
return ";";
case 222:
return "\'";
case 188:
return "<";
case 190:
return ">";
case 191:
return "/";
default:
return "";
}
}
}
}