Search code examples
androidactionscript-3airflash-cs5flashdevelop

How to go back to the previous screen instead of exiting the app on back key pressed


In my Android app when back key pressed the app closed. I want it to go back to the previous screen instead of exiting the app.

While I am using AS3, flash CS5.5.

So what is the code that does that.

Thanks for help.


Solution

  • Intercept Hardware key, and perform your inner logic:

    stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown, false, 0, true);
    
    function onKeyDown(e: KeyboardEvent):void{
        //Back is 94, for Menu key, use 95
        if(e.keyCode == 94){
            //Stop default behaviour
            e.preventDefault();
            //perform your logic
        }
    }