处理iOS主页按钮按下as3

时间:2012-01-17 19:40:36

标签: ios actionscript-3 button handle keycode

我需要帮助检测和处理运行AIR应用程序的iPhone / iPod Touch上按下的主页按钮。我试过了

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

function handleKeys(event:KeyboardEvent):void
{
    if(event.keyCode == Keyboard.HOME) {
         //do something
    }
}
没有运气。有任何想法吗?具体来说,我想在按下主页按钮时阻止应用程序关闭。

1 个答案:

答案 0 :(得分:0)

import flash.events.Event;

addEventListener(Event.ACTIVATE, activateListener);
addEventListener(Event.DEACTIVATE, deactivateListener);

private function activateListener(e:Event):void{
        //do something when awakened

}


private function deactivateListener(e:Event):void{
        //do something when home button is pressed.

}