我有一个程序用作录音平台,每播放一个声音,我都会制作一个新声音。
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?