I'm making a game for Android using AIR (meaning it's programmed in ActionScript 3, same as Flash).
What I'd like to do is to make the physical back button on the phone NOT exit the game, it should pause the game instead. (I will make it so that it will still exit the game if pressed twice rapidly.)
However my code is not working:
public function Main() {
if (Capabilities.cpuArchitecture=="ARM") {
NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, onMainKeyDown);
}
}
private function onMainKeyDown(ke:KeyboardEvent) {
if (ke.keyCode==Keyboard.BACK) {
// Pause the game here.
ke.preventDefault();
ke.stopImmediatePropagation();
}
}
When I publish the thing to my device it still exits when I'm pressing the physical back button on the phone.
What am I doing wrong here?
Edit: There was just a null pointer exception issue I hadn't discovered yet. How embarrassing!
Note that if you’ve set stage.displayState = FULL_SCREEN, no keyboard events are sent to your app! Use stage.displayState = FULL_SCREEN_INTERACTIVE instead!