# attachSound gone - So how can we load random sounds from library?

**URL:** <https://forum.kirupa.com/t/attachsound-gone-so-how-can-we-load-random-sounds-from-library/225561>\
**Category:** flash\
**Created:** [May 13, 2007, 8:16pm UTC](https://forum.kirupa.com/t/attachsound-gone-so-how-can-we-load-random-sounds-from-library/225561 "2007-05-13T20:16:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![K2xL](https://avatars.discourse-cdn.com/v4/letter/k/59ef9b/32.png) [@K2xL](https://forum.kirupa.com/u/K2xL)\
**Post date:** [May 13, 2007, 8:16pm UTC](https://forum.kirupa.com/t/attachsound-gone-so-how-can-we-load-random-sounds-from-library/225561/1 "2007-05-13T20:16:16Z")

</div>

Hi,  
I see that attachSound is gone and you have to instantiate a sound object in replacement.

In other words I can no longer do this:

```php

var S:Sound = new Sound(this);
S.attachSound("SoundLinkedInLibrary");
S.start(0,0);

```

I have to do:

```php

var S:Sound = new SoundLinkedInLibrary();
S.play(0,0);

```

;

However, this is a big problem! I would like to play a random sound from my library! How can I do this without having if statements?

I used to be able to do this:

```php

var S:Sound = new Sound(this);
S.attachSound("MusicTrackNumber"+random(5));
S.start(0,0);

```

But I don’t see a way of doing this in AS 3? It seems like I have to do:

```php

var rand:Number = Math.floor(Math.randon()*5);
var S:Sound;
if (rand == 0)
S = new MusicTrackNumber0();
else if (rand == 1)
S = new MusicTrackNumber1();
else if...

//etc

```

There MUST be a way. Does anyone have any idea or methods they’d like to share?

Thanks!  
-Danny
