-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeys.as
More file actions
42 lines (39 loc) · 881 Bytes
/
Keys.as
File metadata and controls
42 lines (39 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package
{
// adobe
import flash.display.Sprite
import flash.events.KeyboardEvent;
//
// own
//
public class Keys extends Sprite
{
//
static private var keys:Keys;
private var keyObject:Object;
//
//
public function Keys():void {}
/**
* Einmaliges erstellen (Singleton)
*/
static public function init() {
keys = new Keys();
keys.keyObject = { };
View.getStage().addEventListener(KeyboardEvent.KEY_DOWN, keydown);
View.getStage().addEventListener(KeyboardEvent.KEY_UP, keyup);
}
static private function keydown(e:KeyboardEvent):void {
keys.keyObject[e.keyCode] = true;
}
static private function keyup(e:KeyboardEvent):void {
keys.keyObject[e.keyCode] = false;
}
/**
* Interface
*/
static public function press(code:uint):Boolean {
return Boolean(keys.keyObject[code]);
}
}//end-class
}//end-pack