简体   繁体   中英

Actionscript 3: Controlling the physical back button in Android

I'm developing a simple app for Android using ActionScript 3.0 in Flash CS5 and I'd like to know if there's a way to map the physical back button of the Android's phone to tell my animation to go to the first frame.

I've red that post: Disabling the phone's back button (AIR for Android /ActionScript 3)

so maybe it is possible ? If yes HOW.

Thank you !

//first register key down listener

NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);

//then listen to the back key

private function handleKeys(event:KeyboardEvent):void
        {
            if( event.keyCode == Keyboard.BACK ) {
                logDebug("=>handleKeys.");
                NativeApplication.nativeApplication.exit();
            }
        }

Have you tried overriding onKeyUp method?

@Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK) {
            // Do your stuff
        }
        return false;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM