# \[F8AS2\] Sound Manager Class

**URL:** <https://forum.kirupa.com/t/f8as2-sound-manager-class/203381>\
**Category:** flash\
**Created:** [October 10, 2006, 5:36pm UTC](https://forum.kirupa.com/t/f8as2-sound-manager-class/203381 "2006-10-10T17:36:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andir](https://avatars.discourse-cdn.com/v4/letter/a/8797f3/32.png) [@Andir](https://forum.kirupa.com/u/Andir)\
**Post date:** [October 10, 2006, 5:36pm UTC](https://forum.kirupa.com/t/f8as2-sound-manager-class/203381/1 "2006-10-10T17:36:20Z")

</div>

Anyone know why this keeps playing the same sound over and over?

If I call it using:

```auto

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.

```auto
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. Ⓜ
