我是 AS3 的新手,我正在构建一个完整的 flash 网站,我尝试在其中包含背景音乐和播放、暂停和停止按钮(播放和暂停是同一个按钮)。问题是音乐播放器在页面加载时自动播放,当我点击我网站的 HOME 按钮时,音乐再次播放并与首先播放的音乐重叠,所以我该怎么办..提前谢谢
stop();
function goHome (e:MouseEvent):void{
gotoAndStop("HOME");
}
home_btn.addEventListener(MouseEvent.CLICK, goHome);
function goAbout (e:MouseEvent):void{
gotoAndStop("COMPANY");
}
company_btn.addEventListener(MouseEvent.CLICK, goAbout);
function goTestimony (e:MouseEvent):void{
gotoAndStop("TESTIMONY");
}
news_btn.addEventListener(MouseEvent.CLICK, goTestimony);
function goProduct (e:MouseEvent):void{
gotoAndStop("PRODUCT");
}
product_btn.addEventListener(MouseEvent.CLICK, goProduct);
function goContact (e:MouseEvent):void{
gotoAndStop("CONTACT");
}
contacts_btn.addEventListener(MouseEvent.CLICK, goContact);
//imports the necessary as events
import flash.events.Event
import flash.events.MouseEvent;
var isPlaying:Boolean = new Boolean();
var pausePosition:Number = new Number();
//Create an instance of the Sound class
var soundClip:Sound = new Sound();
//Create a new SoundChannel Object
var sndChannel:SoundChannel = new SoundChannel();
//Load sound using URLRequest
soundClip.load(new URLRequest("thousandyears.mp3"));
//Create an event listener that wll update once sound has finished loading
soundClip.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
controller.addEventListener(MouseEvent.MOUSE_DOWN, btnPressController, false, 0, true);
stop_btn.addEventListener(MouseEvent.MOUSE_DOWN, btnPressStop, false, 0, true);
function onComplete(evt:Event):void {
//Play loaded sound
sndChannel = soundClip.play();
isPlaying = true;
}
function btnPressController(evt:MouseEvent):void
{
switch(isPlaying)
{
case true:
controller.gotoAndStop(2);
pausePosition = sndChannel.position;
sndChannel.stop();
isPlaying = false;
break;
case false:
controller.gotoAndStop(1);
sndChannel = soundClip.play(pausePosition);
isPlaying = true;
break;
}
}
function btnPressStop(evt:MouseEvent):void
{
pausePosition = 0;
sndChannel.stop();
controller.gotoAndStop(2);
isPlaying = false;
}