I am trying to play random sounds from an array. Here is the code I am using. Any ideas? this is not working.
import flash.media.Sound;
//var mySound:Sound = new Sound();
var mySoundsArray:Array = ["blue.mp3","green.mp3","red.mp3","yellow.mp3"];
var storedSounds:Array;
for(var i =0; i < mySoundsArray.length; i++)
{
/// DOES NOT WORK BELOW
storedSounds[i] = new Sound();
storedSounds[i].load(new URLRequest("sounds/" + mySoundsArray[i]));
}
/// later to loop through sounds but for now I use the line below default at 0
mySoundsArray[0].play();
You can not use
playmethod tomySoundsArrayelements since they are not sound objects but strings. Try changing last line instoredSounds[0].play()update
this code worked fine for me