我做了一个Flash Air游戏。在玩游戏时,如果我按下Android设备上的Home键,我会进入手机的菜单,但我仍然可以听到游戏的音乐,这意味着游戏仍然可以完全运行。
我希望我的应用程序在不在前台时暂停。
我看过这些代码,但显然我做错了什么,因为它们可能无法工作……
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleApplicationDeactivated);
NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleApplicationActivated);我已经列出了:
import flash.events.Event;
import flash.desktop.NativeApplication;你能帮我找出正确的代码吗?
发布于 2013-04-25 17:12:32
下面的代码将在您按下主页按钮时运行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();
}https://stackoverflow.com/questions/15855239
复制相似问题