我在第1帧(主页)中有一个播放(恢复)/Pause按钮。但是,当用户导航应用程序并决定通过按下Home按钮返回到home Page时,声音会重叠。当用户按下其他按钮时,它开始无休止地重叠。谢谢!这是一个使用Adobe AIR部署在Android设备上的Actionscript 3 Flash应用程序。下面是我的代码:
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.ui.Mouse;
import flash.events.MouseEvent;
var played:Boolean = false;
var soundFile:URLRequest = new URLRequest("music.mp3");
var mySound:Sound = new Sound;
if(played== false){
played= true;
mySound.load(soundFile);
var myChannel:SoundChannel = new SoundChannel;
myChannel = mySound.play(0,999);
pause_btn.addEventListener(MouseEvent.CLICK,pauseSound)
function pauseSound(event:MouseEvent):void
{
var position = myChannel.position;
myChannel.stop();
play_btn.addEventListener(MouseEvent.CLICK,resumeSound);
}
function resumeSound(event:MouseEvent):void
{
myChannel = mySound.play(myChannel.position);
}
}发布于 2017-02-14 13:55:12
这是通过在帧而不是类中编码而得到的。
解决方案A:在第1帧脚本中创建一个类,以便只执行一次(创建主时间线时)。
解决方案B:创建副本前进行检查:
var played:Boolean;
var mySound:Sound;
var myChannel:SoundChannel
// That will be executed only once, because the
// next time this variable will be initialized.
if (mySound == null)
{
played = true;
var soundFile:URLRequest = new URLRequest("music.mp3");
mySound = new Sound;
mySound.load(soundFile);
myChannel = new SoundChannel;
myChannel = mySound.play(0,999);
pause_btn.addEventListener(MouseEvent.CLICK,pauseSound);
}https://stackoverflow.com/questions/42218475
复制相似问题