Flash声音动作开始音乐并自动停止背景声音
问题描述:
我正在使用flash。当我点击MUSIC ON按钮时,我想自动停止背景音,并在点击MUSIC OFF时自动开始(背景音)。Flash声音动作开始音乐并自动停止背景声音
请尽快给我解决方案。
答
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
music_on_btn.addEventListener(MouseEvent.CLICK, onClickStart);
music_off_btn.addEventListener(MouseEvent.CLICK, onClickStop);
function onClickStart(e:MouseEvent):void
{
mySound.load(new URLRequest("myFavSong.mp3"));
myChannel = mySound.play();
}
function onClickStop(e:MouseEvent):void
{
myChannel.stop();
}
更多的查询,你也可以去通过这些链接, http://www.republicofcode.com/tutorials/flash/as3sound/ http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html
希望它可以帮助...
答
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
mySound.load(new URLRequest("mysong.mp3"));
myChannel = mySound.play();
pause_btn.addEventListener(MouseEvent.CLICK, onClickPause);
function onClickPause(e:MouseEvent):void{
lastPosition = myChannel.position;
myChannel.stop();
}
play_btn.addEventListener(MouseEvent.CLICK, onClickPlay);
function onClickPlay(e:MouseEvent):void{
myChannel = mySound.play(lastPosition);
}