禁用手机的返回按钮(Android版AIR / ActionScript 3的) [英] Disabling the phone's back button (AIR for Android /ActionScript 3)

查看:175
本文介绍了禁用手机的返回按钮(Android版AIR / ActionScript 3的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个游戏Andoid使用AIR(这意味着它编程在ActionScript 3,同为Flash)。

我想要做的就是使手机上的物理后退按钮不会退出比赛,就应该暂停比赛代替。 (我将让这个它仍然会退出比赛,如果pressed两次迅速。)

不过我的code不工作:

 公共函数main(){
    如果(Capabilities.cpuArchitecture ==ARM){
        NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN,onMainKeyDown);
    }
}
 

 私有函数onMainKeyDown(柯:KeyboardEvent的){
    如果(ke.key code == Keyboard.BACK){
        //这里暂停游戏。
        柯preventDefault()。
        ke.stopImmediatePropagation();
    }
}
 

当我发布的东西到我的设备仍然退出,当我pressing手机上的物理后退按钮。

我在做什么错在这里?

-

等一下,它的工作。这里只是我还没有发现又一个空指针异常问题。

多么尴尬!

可否自行回答quastion但我不能,除非8小时过去了,因为我问。这是对计算器的最愚蠢的事情(可能是唯一的愚蠢的事情我能想到的......好吧,没关系,以后的事实,单换行符本身不会显示为pretty的哑太)。

解决方案

  NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN,的onkeydown,假,0,TRUE)

功能的onkeydown(事件:KeyboardEvent的):无效
{
    如果(event.key code == Keyboard.BACK)
{
    。事件preventDefault();
    event.stopImmediatePropagation();
    //这里处理按钮preSS。
   }
}
 

请注意,如果你设置stage.displayState = FULL_SCREEN,没有键盘事件发送到你的应用程序!使用stage.displayState = FULL_SCREEN_INTERACTIVE,而不是!

I'm making a game for Andoid using AIR (meaning it's programmed in ActionScript 3, same as Flash).

What I'd like to do is to make the physical back button on the phone NOT exit the game, it should pause the game instead. (I will make it so that it will still exit the game if pressed twice rapidly.)

However my code is not working:

public function Main() {
    if (Capabilities.cpuArchitecture=="ARM") {
        NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, onMainKeyDown);
    }
}

private function onMainKeyDown(ke:KeyboardEvent) {
    if (ke.keyCode==Keyboard.BACK) {
        // Pause the game here.
        ke.preventDefault();
        ke.stopImmediatePropagation();
    }
}

When I publish the thing to my device it still exits when I'm pressing the physical back button on the phone.

What am I doing wrong here?

--

Hang on, it did work. There was just a null pointer exception issue I hadn't discovered yet.

How embarrassing!

Would self-answer the quastion but I can't unless 8 hours have passed since I asked. That's the dumbest thing about stackoverflow (might be the only dumb thing I can think of... well, ok maybe the fact that single line-breaks won't show up by itself is pretty dumb too).

解决方案

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

function onKeyDown(event:KeyboardEvent):void
{
    if( event.keyCode == Keyboard.BACK )
{
    event.preventDefault();
    event.stopImmediatePropagation();
    //handle the button press here. 
   }
}

Note that if you’ve set stage.displayState = FULL_SCREEN, no keyboard events are sent to your app! Use stage.displayState = FULL_SCREEN_INTERACTIVE instead!

这篇关于禁用手机的返回按钮(Android版AIR / ActionScript 3的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆