1

我正在创建一个带有多语言旁白的多语言 Flash 游戏。到目前为止,我已经有了一种带有音频流和歌词的语言,可以在它自己的时间线上伴随它,由主时间线上的按钮控制以暂停和播放。我想为这个场景中的每种语言添加另外 2 种带有音频和自己的歌词(卡拉 OK 风格)的语言。最终在主时间线上有按钮可以切换语言(音频和歌词)并从最后一种语言停止的地方无缝地继续。到现在为止,我从主时间线控制音频和歌词的这个动作。englyr 是影片剪辑,其中包含音频和歌词。

toggleButton.addEventListener(MouseEvent.CLICK, toggleClick3);
toggleButton.buttonState = "off";

function toggleClick3(event:MouseEvent) {
    if (toggleButton.buttonState == "on") {
        englyr.play();
        toggleButton.buttonState = "off";
    } else {
        toggleButton.buttonState = "on";
        englyr.stop();
    }
}

我假设我应该将其他 2 种语言及其歌词放在 englyr 中,以便我可以禁用/静音不需要听到或看到的语言。一个问题是我无法将歌词和旁白(2 层)组合在一起作为该时间轴中的影片剪辑。因此不能禁用不应该听到或看到的其他 2 种语言。有什么解决办法吗?

4

1 回答 1

0

让它们都从代码而不是通过时间线播放可能更容易。首先要做的是转到库中音频剪辑的设置,启用“Export for Actionscript”并为两个剪辑设置不同的类名。我将我的命名为“英语”和“法语”。当您按下当前未播放的语言的按钮时,以下代码管理两种声音并更改语言。

var englishClip:Sound = new english(); //load both sounds.
var frenchClip:Sound = new french();

//create the sound and the sound channel.
var myChannel:SoundChannel = new SoundChannel();
var mySound:Sound = englishClip;

//if you want to have lots of different languages it might be easier to just have different buttons instead of one with a state.
englishButton.addEventListener(MouseEvent.CLICK, SpeakEnglish);
frenchButton.addEventListener(MouseEvent.CLICK, SpeakFrench);

//we'll start with having just the english sound playing.
myChannel = mySound.play();

function SpeakEnglish(event:MouseEvent) {
    if (mySound != englishClip) { //if the english sound is already playing, do nothing.
        var currentPlayPosition:Number = myChannel.position; //save playback position.
        myChannel.stop(); //stop playing
        mySound = englishClip.play(currentPlayPosition); //resume playing from saved position.
}

function SpeakFrench(event:MouseEvent) {
    if (mySound != frenchClip) { //if the French sound is already playing, do nothing.
        var currentPlayPosition:Number = myChannel.position; //save playback position.
        myChannel.stop(); //stop playing
        mySound = frenchClip.play(currentPlayPosition); //resume playing from saved position.
}

这一切都可以通过使用一个将适当的声音传递给的函数来变得更加紧凑。它看起来像这样:

function SpeakEnglish(event:MouseEvent) {
    ChangeSound(englishClip);
}

function SpeakFrench(event:MouseEvent) {
    ChangeSound(frenchClip);
}

function ChangeSound(newSound:Sound){
    if (mySound != newSound) { //if the sound is already playing, do nothing.
        var currentPlayPosition:Number = myChannel.position; //save playback position.
        myChannel.stop(); //stop playing
        mySound = newSound.play(currentPlayPosition); //resume playing from saved 
}

那应该可以解决问题,我希望对您有所帮助:)

资源:http ://www.republicofcode.com/tutorials/flash/as3sound/

于 2013-06-17T10:45:10.027 回答