如何在Flash中的AS3脚本中为现有歌曲再添加2首歌曲



作为Flash CS6动作脚本3的新手,有人能具体地举一个详细的例子吗?请向我解释如何在我的播放器中再添加两首歌曲,并且仍然使用当前的播放和暂停按钮来控制它们?

非常感谢!

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);
}

我只是假设有四个标题/标题按钮和四个标题通道来编写这个示例代码。我有一个声音频道的标题声音。我可以用它来停止、暂停或播放声音。简单地说,我可以使用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);
}

如果您想像其他声音一样暂停并继续播放标题,请像在函数onClickPauseonClickPlay中对myChannel所做的操作一样。

注意:如果您想为某个事件播放声音(如背景或爆炸或其他事件),并且该事件经常发生,那么请毫不犹豫地为该声音提供SoundChannel实例来控制该声音。

最新更新