-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKeyboardEventExample.as
More file actions
36 lines (31 loc) · 1.19 KB
/
Copy pathKeyboardEventExample.as
File metadata and controls
36 lines (31 loc) · 1.19 KB
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
package {
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.events.*;
import Display;
public class KeyboardEventExample extends Sprite {
private var bgColor:uint = 0x00CCFF;
private var size:uint = 80;
public function KeyboardEventExample() {
var child:Sprite = new Sprite();
child.graphics.beginFill(bgColor);
child.graphics.drawRect(0, 0, size, size);
child.graphics.endFill();
Display.addchild(this);
addChild(child);
stage.focus = child;
child.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
child.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
}
private function keyDownHandler(event:KeyboardEvent):void {
trace("keyDownHandler: " + event.keyCode);
trace("ctrlKey: " + event.ctrlKey);
trace("keyLocation: " + event.keyLocation);
trace("shiftKey: " + event.shiftKey);
trace("altKey: " + event.altKey);
}
private function keyUpHandler(event:KeyboardEvent):void {
trace("keyUpHandler: " + event.keyCode);
}
}
}