我制作了Flash Air游戏。在播放时,如果我按下Android设备上的主页按钮,我会看到手机的菜单,但我仍然可以听到游戏的音乐,这意味着游戏仍然可以继续完全正常工作。
我希望我的应用在不在前台时暂停。
我见过这些代码,但显然我做错了,因为它们可能不起作用......
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleApplicationDeactivated);
NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleApplicationActivated);
我列出了:
import flash.events.Event;
import flash.desktop.NativeApplication;
你能用正确的代码帮助我吗?
答案 0 :(得分:0)
下面的代码将在您按下主页按钮时运行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();
}