Anyone know why this keeps playing the same sound over and over?
If I call it using:
var sounds:src.snd.SoundManager = new src.snd.SoundManager(); // This isn't how I do it, but ... you understand.
sounds.queueSound('libsound1');
sounds.queueSound('libsound2');
sounds.queueSound('libsound3');
sounds.queueSound('libsound4');
it will play ‘libsound1’ four(4) times.
import mx.utils.Delegate;
class src.snd.SoundManager {
private var snd:Sound;
private var sndQueue:Array;
public function SoundManager() {
snd = new Sound();
sndQueue = new Array();
snd.onSoundComplete = Delegate.create(this, onSoundComplete);
}
public function onSoundComplete() {
if (snd.position >= snd.duration) {
if (sndQueue.length > 0) {
var nextSound = sndQueue.shift();
playSound(nextSound);
}
}
}
public function queueSound(libName:String) {
sndQueue.push(libName);
onSoundComplete();
}
private function playSound(libName:String) {
snd.attachSound(libName);
snd.start();
}
}
If I trace nextSound, it shows:
libsound1
libsound2
libsound3
libsound4
I get the same result if I trace libName in the playSound function.
For some reason the attachSound is not changing library sounds.