録音プラットフォームとして使用するプログラムがあり、再生するサウンドごとに新しいサウンドを作成します。
public function playAudioFile():void {
trace("audio file:", currentAudioFile);
sound = new Sound();
sound.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
sound.addEventListener(Event.COMPLETE, soundLoaded);
sound.load(new URLRequest(soundLocation + currentAudioFile));
}
public function soundLoaded(event:Event):void {
sound.removeEventListener(IOErrorEvent.IO_ERROR, errorHandler);
sound.removeEventListener(Event.COMPLETE, soundLoaded);
var soundChannel:SoundChannel = new SoundChannel();
soundChannel = sound.play();
soundChannel.addEventListener(Event.SOUND_COMPLETE, handleSoundComplete);
trace('soundChannel?', soundChannel);
}
public function handleSoundComplete(event:Event):void {
var soundChannel:SoundChannel = event.target as SoundChannel;
soundChannel.stop();
soundChannel.removeEventListener(Event.SOUND_COMPLETE,handleSoundComplete);
soundChannel = null;
}
32 回後、sound.play() (soundLoaded 内) を呼び出したときに、SoundChannel オブジェクトの取得を停止しました。ただし、32 個の SoundChannel オブジェクトを用意する必要はありません。これらのサウンドは、同時にではなく連続して再生するからです。ファイルの再生に使用した後、SoundChannel を削除するにはどうすればよいですか?