Reputation: 33
I want to prevent default function of back and menu key and bring up an exit menu at the bottom.. My problem is, when I have a text input function in my app everytime a key is pressed in general brings up the exit menu i created at the bottom and then closes the menu over and over again..
Sorry If I'm being too vague.. here's my code..
"options_mc" is my exit menu I've created.
options_mc.visible = false;
function fl_ExitApplication(event:MouseEvent):void
{
NativeApplication.nativeApplication.exit(0);
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_OptionsMenuHandler);
function fl_OptionsMenuHandler(event:KeyboardEvent):void
{
if((event.keyCode == 95) || (event.keyCode == Keyboard.MENU, Keyboard.DOWN))
{switch (event.keyCode)
{case Keyboard.BACK:
event.preventDefault();
trace("back");}
}
{
if(options_mc.visible == false){
options_mc.visible = true;
options_mc.addEventListener(MouseEvent.CLICK, fl_ExitApplication);
} else if(options_mc.visible == true){
options_mc.visible = false;
options_mc.removeEventListener(MouseEvent.CLICK, fl_ExitApplication);
}
}
}
Upvotes: 1
Views: 907
Reputation: 10640
Override the onBackPressed() method in activity
@Override
public void onBackPressed() {
super.onBackPressed();
finish();
}
It will stop the activity, ANother way is implementing action menus, see this example
Upvotes: 1