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:
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.