有人可以,特别是详细的例子,因为我是Flash CS6动作脚本3的新手,向我解释如何向我的播放器添加2首歌曲,并仍然用当前播放和暂停来控制它们按钮?
非常感谢!
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.MouseEvent;
var mySound:Sound = new heyjude();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
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.stop()
myChannel = mySound.play(lastPosition);
}
答案 0 :(得分:0)
我写了这个示例代码,假设有四个标题/标题按钮,因此有四个标题频道。我有一个标题声音的声道。我可以停止或暂停或播放声音。简单地说,我可以使用titleChannel
控制标题声音。
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.MouseEvent;
var titleSound1:Sound = new TitleSound1();
var titleSound2:Sound = new TitleSound2();
var titleSound3:Sound = new TitleSound3();
var titleSound4:Sound = new TitleSound4();
var mySound:Sound = new heyjude();
var titleChannel:SoundChannel;
var myChannel:SoundChannel;
var lastPosition:Number = 0;
titleBtn1.addEventListener(MouseEvent.CLICK, title1Selected);
titleBtn1.addEventListener(MouseEvent.CLICK, title2Selected);
titleBtn1.addEventListener(MouseEvent.CLICK, title3Selected);
titleBtn1.addEventListener(MouseEvent.CLICK, title4Selected);
play_btn.addEventListener(MouseEvent.CLICK, onClickPlay);
pause_btn.addEventListener(MouseEvent.CLICK, onClickPause);
function title1Selected(e:MouseEvent){
if(titleChannel != null) titleChannel.stop();
titleChannel = titleSound1.play();
}
function title2Selected(e:MouseEvent){
if(titleChannel != null) titleChannel.stop();
titleChannel = titleSound2.play();
}
function title3Selected(e:MouseEvent){
if(titleChannel != null) titleChannel.stop();
titleChannel = titleSound3.play();
}
function title4Selected(e:MouseEvent){
if(titleChannel != null) titleChannel.stop();
titleChannel = titleSound4.play();
}
function onClickPause(e:MouseEvent):void{
lastPosition = myChannel.position;
myChannel.stop();
}
function onClickPlay(e:MouseEvent):void{
myChannel.stop()
myChannel = mySound.play(lastPosition);
}
如果你想像其他声音一样暂停和恢复播放标题声音,那么就像你在myChannel
和onClickPause
函数中对onClickPlay
所做的那样。< / p>
注意:如果您想为某个事件(如背景或爆炸或其他事件)播放声音,并且如果该事件经常发生,那么请不要犹豫,为此事件设置SoundChannel
个实例声音来控制那个声音。