NativeApplication将DEACTIVATE-ACTIVATE应用程序在背景中时 [英] NativeApplication DEACTIVATE-ACTIVATE app when in the background
问题描述
我做了一个Flash游戏的空气。在播放时,如果我$ Android设备在页码$ PSS的主页按钮,我得到了手机的菜单但我仍然可以听游戏的音乐,这意味着游戏仍然保持在完全工作。
I have made a Flash Air game. While playing it, if I press the Home button on my Android device, I get to the phone's menu yet I still get to listen to the game's music, which means that the game still keeps on fully working.
我想我的应用程序暂停时,不在前台。
I would like my app to pause when not in the foreground.
我已经看到了这些codeS,但显然我做错了什么原因,他们没有工作可能......
I've seen these codes but apparently I'm doing something wrong cause they aren't working probably...
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleApplicationDeactivated);
NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleApplicationActivated);
我已经列出了:
I've listed the:
import flash.events.Event;
import flash.desktop.NativeApplication;
你能不能帮我正确的code?
Could you help me with the proper code?
推荐答案
在code以下将要运行的onPause当你当你PSS home键$ P $和onResume回到你的应用程序。 SoundMixer.stopAll();将停止正在播放的所有声音。
The code below will run the onPause when you press the home button, and onResume when you get back in your app. SoundMixer.stopAll(); will stop ALL sounds that are playing.
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();
}
这篇关于NativeApplication将DEACTIVATE-ACTIVATE应用程序在背景中时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!