Answered
(AS3) Sort and Sound.play() issues
There are over 2000 songs in the remote directory.
In this case, might "sound.play()" be executed first before "sort()" completes?
So is there a way to prevent this?
I would greatly appreciate it if you could let me know the sample code.
var channel: SoundChannel;
var sound: Sound;
var n:uint;
var dm: String = "http://.../Music/";
var sm: Array = [ Music list of over 2000 songs ];
sm.sort(1);
n = Math.floor(Math.random() * (sm.length-1));
musicPlay(sm[n]);
function musicPlay(url: String): void {
if (channel) channel.stop();
n = sm.indexOf(url);
url = dm + url + ".mp3";
sound = new Sound(new URLRequest(url));
channel = new SoundChannel();
sound.addEventListener(ProgressEvent.PROGRESS, progressHandler);
channel = sound.play(0);
}