# Loading songs into flash

**URL:** <https://forum.kirupa.com/t/loading-songs-into-flash/192844>\
**Category:** flash\
**Created:** [July 1, 2006, 10:10pm UTC](https://forum.kirupa.com/t/loading-songs-into-flash/192844 "2006-07-01T22:10:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![riveroaks](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@riveroaks](https://forum.kirupa.com/u/riveroaks)\
**Post date:** [July 1, 2006, 10:10pm UTC](https://forum.kirupa.com/t/loading-songs-into-flash/192844/1 "2006-07-01T22:10:42Z")

</div>

I’m trying to put together a simple music player for my flash site and I’m thinking I want to dynamically load external MP3’s into the site rather than placing the songs in my library. I also want the system to be versatile so I can add and remove songs at will so I set up some actionscript that works in a loop to try and load songs until it cant find a given song. My actionscript is as follows:

```auto
var songArray = new Array();

songObj = new Sound();
i = 1;
testSong = "song" + i + ".mp3";
songObj.loadSound(testSong, false);
while(songObj.getBytesTotal() > 0) {
	songArray.push(testSong);
	i++;
	testSong = "song" + i + ".mp3";
	songObj.loadSound(testSong, false);
}

```

the problem is that when flash tries to load a song that doesn’t exist it reports an error and stops executing my script. How can I get around this? Are there try and catch abilities in actionscript like there are in Java? Or is there some way through actionscript to figure out whether a given song is available before trying to load it? Or further is there a better way of doing what it is im trying to do? Thanks.
