1

ステージに 4 つのボタンがあり、そのうちの 1 つをクリックして特定のサウンドを「無限に」ループさせ、もう一度クリックするとサウンドが停止するコードが必要です。サウンドは最初から再生されていません。また、音のループ中に別のボタンを押すと、前の音を止めて新しい音を鳴らしたいです。

これをさらに視覚化するために、私のプロジェクトについて説明します。オンライン ギター チューナーのような「アプリ」を作成する必要があります。この機能は、私が再作成したいものです。

http://www.gieson.com/Library/projects/utilities/tuner/

コーディングをどこから始めればよいかさえわかりません...どんな助けも大歓迎です。ありがとうございました!

4

1 に答える 1

0

実際のコードはサウンドの読み込み方法に大きく依存するため、コードの「スケルトン」を記述します。

var currentSound:Sound = null;
var currentSoundChannel:SoundChannel;

var sound1:Sound = /* Load me */
var sound2:Sound = /* Load me */


button1.addEventListener(MouseEvent.CLICK, playSound1);
function playSound1(event:MouseEvent)
{
    playSound(sound1);
}

button2.addEventListener(MouseEvent.CLICK, playSound2);
function playSound2(event:MouseEvent)
{
    playSound(sound2);
}


function playSound(sound:Sound):void
{
    if (currentSound != null)
    {
        // Stop the current music
        currentSoundChannel.stop();
    }

    if (currentSound == sound)
    {
        // Stop playing ANY sound
        currentSound = null;
        currentSoundChannel = null;
    }
    else
    {
        // Play a different sound
        currentSound = sound;
        currentSoundChannel = sound.play();
    }
}
于 2012-12-30T11:43:39.327 に答える