# Playing a sound via listbox

**URL:** <https://forum.kirupa.com/t/playing-a-sound-via-listbox/73952>\
**Category:** Uncategorized\
**Created:** [December 22, 2004, 5:17am UTC](https://forum.kirupa.com/t/playing-a-sound-via-listbox/73952 "2004-12-22T05:17:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haxorleet](https://avatars.discourse-cdn.com/v4/letter/h/8491ac/32.png) [@Haxorleet](https://forum.kirupa.com/u/Haxorleet)\
**Post date:** [December 22, 2004, 5:17am UTC](https://forum.kirupa.com/t/playing-a-sound-via-listbox/73952/1 "2004-12-22T05:17:00Z")

</div>

I’ve been having some trouble with the coding on this, I know I’m doing a little thing wrong with thsi but I can’t figure it out. I want it to play a song (from a URL) by selecting it in a listbox.

I made a listbox and named it “songs”

```auto
//randomize
x = Math.round((Math.random()) * 4)
songs.setSelectedIndex(x);

music = new Sound(this);
y = getSelectedIndex();
if(y==0){
	songurl="http://www.haxorl33t.com/mp3/trust.mp3";
}
if(y==1){
	songurl="http://www.haxorl33t.com/mp3/glory.mp3";
}
if(y==2){
	songurl="http://www.haxorl33t.com/mp3/risen.mp3";
}
if(y==3){
	songurl="http://www.haxorl33t.com/mp3/rules.mp3";
}
if(y==4){
	songurl="http://www.haxorl33t.com/mp3/waste.mp3";
}
music.loadSound(songurl,true);

```

any help is much appreciated, thanks…
