Skip to content

Instantly share code, notes, and snippets.

@jgranick
Created February 21, 2012 16:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgranick/1877209 to your computer and use it in GitHub Desktop.
Save jgranick/1877209 to your computer and use it in GitHub Desktop.
How to override the back button on Android (NME recipe)
import nme.display.Sprite;
import nme.Lib;
/**
* @author Joshua Granick
*/
class BackButtonExample extends Sprite {
public function new () {
super ();
Lib.current.stage.addEventListener (KeyboardEvent.KEY_UP, stage_onKeyUp);
}
private function stage_onKeyUp (event:KeyboardEvent):Void {
#if android
if (event.keyCode == 27) {
event.stopImmediatePropagation ();
Lib.exit ();
}
#end
}
}
@thomasuster
Copy link

Anyone know if this works in latest NME? Doesn't work for me.

@thomasuster
Copy link

Upgrade to openfl 1.0.4 works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment