在Adobe Flash中无缝切换语言(音频和歌词)

时间:2013-06-17 08:41:34

标签: actionscript-3 flash audio adobe

我正在创建一个多语言故事的多语言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();
    }
}

我假设我应该将其他两种语言以及它们的歌词放入englyr中,以便我可以禁用/静音不需要听到或看到的语言。一个问题是我不能将歌词和叙述(2层)组合在一起作为该时间线中的电影剪辑。因此无法禁用其他2种不应该被听到或看不到的语言。任何解决方案?

1 个答案:

答案 0 :(得分:0)

让他们从代码而不是通过时间线玩游戏可能更容易。 首先要做的是转到库中的audioclips设置,启用“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/