google code prettify

2012年1月31日 星期二

[ActionScript 3] 按下退出或 Home 按鈕就能夠自動關閉 Android AIR app

[ActionScript 3] 按下退出或 Home 按鈕就能夠自動關閉 Android AIR app

//註冊NativeApplication針對Event事件的監聽
NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE,handleActivate, false, 0, true);


NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE,handleDeactivate, false, 0, true);


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

//處理對應的事件邏輯
function handleActivate(event:Event):void {
        //保持AIR程式正常使用
        NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}

function handleDeactivate(event:Event):void {
        //關閉AIR程式
        NativeApplication.nativeApplication.exit();
} 

function handleKeys(event:KeyboardEvent):void {
        //當按鍵BACK鍵,關閉AIR程式
        if(event.keyCode == Keyboard.BACK) {
                NativeApplication.nativeApplication.exit();
        }
}


轉貼自:
http://www.iyoume.net/profiles/blogs/exit-android-air-app-as3#axzz1kxPhOXIX



沒有留言:

張貼留言