【问题标题】:NativeApplication DEACTIVATE-ACTIVATE app when in the backgroundNativeApplication DEACTIVATE-ACTIVATE 应用在后台时
【发布时间】:2013-04-06 19:42:19
【问题描述】:

我制作了一款 Flash Air 游戏。在玩游戏时,如果我按下 Android 设备上的 Home 按钮,我会进入手机菜单,但我仍然可以听游戏的音乐,这意味着游戏仍然可以正常运行。

我希望我的应用在不在前台时暂停。

我已经看过这些代码,但显然我做错了什么,因为它们可能无法正常工作......

NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleApplicationDeactivated);
NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleApplicationActivated);

我列出了:

import flash.events.Event;
import flash.desktop.NativeApplication;

你能帮我写出正确的代码吗?

【问题讨论】:

    标签: android actionscript-3 air


    【解决方案1】:

    下面的代码将在您按下主页按钮时运行 onPause,并在您返回应用程序时运行 onResume。 SoundMixer.stopAll();将停止所有正在播放的声音。

        this.stage.addEventListener(flash.events.Event.DEACTIVATE, onPause, false, 0, true);
    
        this.stage.addEventListener(flash.events.Event.ACTIVATE, onResume, false, 0, true);
    
    
    
        private function onPause(event:flash.events.Event):void
        {
    
            //here save your games state.
    
            //then stop ALL sound from playing with the following line:
            SoundMixer.stopAll();
            //Remember to import flash.media.SoundMixer;
    
        }
        private function onResume(event:flash.events.Event):void
        {
             //here you start the sounds again, for example: 
            sound.play();
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-11
      • 1970-01-01
      • 1970-01-01
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多