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

MySong.play();

But suppose we get a string like;

id:String;

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
id.play();
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');
song.play();
1 Like

hi,
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:
anthony