Topic: Game Programming /
Seriously WTF | Works in flashdevelop, doesn't in browser. FIXD
Originally posted by UnknownGuardian:
I prefer to not download/open the zip. Could you post the class that you used to get keyboard presses
sure.
All the way on top
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
further down (in main)
stage.focus = this; //First some focus.
addEventListener(Event.ENTER_FRAME, onEnterFrame); //the standard event listeners
addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown); //and the one giving me problems
and of course the onKeyDown function
private function onKeyDown(e:KeyboardEvent):void {
if (vertical){
if (e.keyCode == Keyboard.LEFT) { left = true; right = false; up = false; down = false; }
else if (e.keyCode == Keyboard.RIGHT) { right = true; left = false; up = false; down = false; }
} else if (horizontal){
if (e.keyCode == Keyboard.UP) { up = true; down = false; left = false; right = false; }
else if (e.keyCode == Keyboard.DOWN) { down = true; up = false; left = false; right = false; }
}
if (e.keyCode == Keyboard.ESCAPE && dead) { reset(); }
horizontal = false;
vertical = false;
}
|