Playing with flash keyboard click events
Submitted by litwol on Sun, 01/17/2010 - 23:51
Incredibly simple flash app that demonstrates simple key controls.
Use key up, down, left, and right to control the grey rectangle.
For this code to work you are required to create a rectangle movie clip instance called 'rect_mc'.
Note to self: Learn how to create simple shapes programmatically.
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
function keyDownHandler(event:KeyboardEvent): void {
if ( event.keyCode == Keyboard.LEFT ) {
rect_mc.x -= 5;
}
else if ( event.keyCode == Keyboard.UP) {
rect_mc.rotationX -= 5;
}
else if ( event.keyCode == Keyboard.RIGHT) {
rect_mc.x += 5;
}
else if ( event.keyCode == Keyboard.DOWN) {
rect_mc.rotationX +=5;
}
}
- 3292 reads
Tags: