Using a String as a sound name

hi all,

Pardon my low knowledge and my cheap explanation :frowning:

when we assign a sound it’s like:

var Mysong:Sound;

and later we use it as;

But suppose we get a string like;


and later that id is assigned a value;

id = MySong;

Now since there is also a sound named MySong, Is there a way I could play this String as a sound ?
I tried;
but failed

In short,is there a way I could use/get a sound by a string ?

In short, yes :slight_smile:

Here is the sample code

var url:String = "path/to/sound.mp3"
var soundRequest = new URLRequest(url);
var mySound = new Sound(soundRequest);

Hope that helps

1 Like

Maybe you can use StringMap?

var songs = new StringMap<Sound>();
songs.set('song_id', mySong);

And later:

var song = songs.get('song_id');;
1 Like

thanks very much for the replies :slight_smile:

Interestingly both the solutions given worked and solved my problem!, ( while earlier i was frustrated about this problem before creating this topic)
it’s good for me as both the ways are working for me…
Thanks very much for your efforts! :slight_smile: