這太奇怪了,這篇文章不會讓我用你好開始句子嗨或者你可能緩存問題,反正,你好,我對AS3非常新,所以我的知識是有限的,希望你的專業人員可以輕鬆地對新人:)。 我正在建立一個動畫循環的Flash網站,我已經添加了一首mp3歌曲作爲背景音樂,它也設置爲循環播放和自動播放。問題在於,歌曲比動畫長,當動畫回到第1幀時,歌曲與仍在播放的歌曲重疊。我希望這首歌完全完成,然後再開始播放。 yeaaah可能有一堆代碼缺失,但我更接近我想要的東西,只需要你的幫助來擦亮它一點。mp3循環問題 - Actionscript 3
這裏是到目前爲止的代碼
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.net.URLRequest;
//var codes
var AutoPlay:Boolean=true;
var isPlaying:Boolean=false;
var pausePosition:Number=0;
var myMusic:Sound=new Sound();
var soundFile:URLRequest=new URLRequest("Fluke.mp3");
myMusic.load(soundFile);
var channel:SoundChannel;
//if commands
if (AutoPlay==true) {
channel=myMusic.play(pausePosition);
isPlaying=true;
}
//pausebutton functions
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
function pauseSound(e:MouseEvent):void
{
if (isPlaying == false) {
channel = myMusic.play(pausePosition);
isPlaying =true;
}else{
pausePosition=channel.position;
channel.stop();
isPlaying=false;
}
}
//playbutton functions
play_btn.addEventListener(MouseEvent.CLICK,playMus ic);
function playMusic(event:MouseEvent):void
{ if (isPlaying== false) {
channel=myMusic.play(pausePosition);
isPlaying=true;
}
}
這是完整的工作代碼感謝Josha,與我添加了一個閱讀進度,使這首歌將其播放完後循環。
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.net.URLRequest;
//var codes
var AutoPlay:Boolean=true;
var isPlaying:Boolean;
var pausePosition:Number;
var myMusic:Sound;
var soundFile:URLRequest;
var channel:SoundChannel;
// only create music and register event listeners one time
if (myMusic == null)
{
soundFile = new URLRequest("Fluke.mp3");
myMusic = new Sound();
myMusic.load(soundFile);
pausePosition = 0;
if (AutoPlay)
{
channel = myMusic.play(pausePosition);
isPlaying = true;
}
else
{
isPlaying = false;
}
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
play_btn.addEventListener(MouseEvent.CLICK, playMusic);
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
function onPlaybackComplete(event:Event) {
pausePosition = 0;
channel = myMusic.play(pausePosition);
isPlaying = true;
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}
//playbutton functions
function pauseSound(e:MouseEvent):void
{
if (isPlaying == false) {
channel = myMusic.play(pausePosition);
isPlaying =true;
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}else{
pausePosition=channel.position;
channel.stop();
isPlaying=false;
}
}
//playbutton functions
function playMusic(event:MouseEvent):void
{
if (isPlaying== false) {
channel=myMusic.play(pausePosition);
isPlaying=true;
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}
}
夥計,太感謝你了,我會疲於摸不着頭腦。我必須添加一個事件監聽器,以便它可以循環。對於像我這樣試圖做同樣的工作的所有新手,感謝Josha的完整工作代碼在我的第一篇文章中進行了編輯。 – 4Geist
歡迎您:)快樂編碼;如果您要添加更多動作,您可能想了解如何將MovieClip鏈接到外部動作文件。 – Josha