我正在创建一个具有多语言解说的多语言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层)组合在一起,作为该时间线上的一个电影剪辑。因此,不能禁用其他两种不应该听到或看到的语言。有什么解决方案吗?
发布于 2013-06-17 18:45:10
让它们都从代码中播放可能比通过时间线播放更容易。要做的第一件事是转到库中音频剪辑的设置,启用"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/
https://stackoverflow.com/questions/17143503
复制相似问题