我有一個播放(恢復)/第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