首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NativeApplication停用-在后台激活应用程序

NativeApplication停用-在后台激活应用程序
EN

Stack Overflow用户
提问于 2013-04-07 03:42:20
回答 1查看 3.7K关注 0票数 1

我做了一个Flash Air游戏。在玩游戏时,如果我按下Android设备上的Home键,我会进入手机的菜单,但我仍然可以听到游戏的音乐,这意味着游戏仍然可以完全运行。

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

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

代码语言:javascript
复制
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleApplicationDeactivated);
NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleApplicationActivated);

我已经列出了:

代码语言:javascript
复制
import flash.events.Event;
import flash.desktop.NativeApplication;

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

EN

回答 1

Stack Overflow用户

发布于 2013-04-25 17:12:32

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

代码语言:javascript
复制
    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();

    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15855239

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档