我有一个播放(恢复)/第1帧中暂停按钮(主页)。但是,当用户导航应用程序并通过按主页按钮决定返回主页时,声音重叠。而当用户按下其他按钮时,它开始无休止地重叠。谢谢!这是一个使用Adobe AIR在Android设备上部署的Actionscript 3 Flash应用程序。这是我的代码:重叠的声音的ActionScript 3/AIR
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);
}
}
不要在时间轴使用初始化代码。除非'myChannel'中有一个有效的'SoundChannel',否则不要启动声音,这需要更多的检查。另外''位置'是'pauseSound()'中的本地函数,移动到全局位置,否则您将丢失数据并且无法恢复您的声音。 – Vesper
@Vesper谢谢你!我是Flash的初学者,请耐心等待。你能否给我你的版本更正的代码?谢谢! – niagrafallsxxx