-
1. Re: Flash Builder Mobile app and handling the hardware Back button
Shongrunden Aug 23, 2011 6:49 PM (in response to rtalton)Try having a backKeyPressed handler that calls event.preventDefault(); event.stopImmediatePropagation();
-
2. Re: Flash Builder Mobile app and handling the hardware Back button
rtalton Aug 24, 2011 8:36 AM (in response to Shongrunden)Tried backKeyPressed with preventDefault & stopImmediatePropagation: it didn't work either.
In case it would help anyone else, here's the way I got it to work in my TabbedViewNavigatorApplication:
In each top-most View in each tab that you want to prevent the default back key press from exiting the app, add a handler to the ViewActivate event
//add the keyboard listener:
stage.addEventListener(KeyboardEvent.KEY_DOWN, _onKeyDown);In this View's Deactivate event listener, add this:
//removes the _onKeyDown listener from this view when
//the view is deactivated:
stage.removeEventListener(KeyboardEvent.KEY_DOWN, _onKeyDown);Finally, the function which does the job of preventing accidentally exiting the app:
private function _onKeyDown(event:KeyboardEvent):void {
if (event.keyCode == Keyboard.BACK) {
event.preventDefault();
//Return user to the "Home" view, where they can exit if they wish.
this.parentApplication.tabbedNavigator.selectedIndex=0;
} else if (event.keyCode == Keyboard.MENU) {
//unused
//event.preventDefault();
} else if (event.keyCode == Keyboard.SEARCH) {
//unused
//event.preventDefault();
}
}This is based on code I got here:
but was based on the added to stage event, and i had issues with making that work as it was firing from every view and was difficult to sort out a condition to actually supress the event. So the way I've done it, I know which view fired the event as it can only originate from a single view while it is active.
Hope this helps someone researching the same issue in the future.



