タイムライン経由ではなく、コードから両方を再生できるようにする方がおそらく簡単です。最初に行うことは、ライブラリ内のオーディオ クリップの設定に移動し、[Actionscript 用にエクスポート] を有効にして、両方のクリップに異なるクラス名を設定することです。私は自分の名前を「英語」と「フランス語」にしました。次のコードは、2 つのサウンドを管理し、現在再生されていない言語のボタンを押したときに言語を変更します。
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/