I have 2 buttons in my AS3 project that load .mp3 files and then play them. I have 2 buttons that switch between those files that aren’t working. I get an error saying:
Error: Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.
at flash.media::Sound/_load()
at flash.media::Sound/load()
at player_fla::MainTimeline/playMusic1()
I’m thinking that means the file isn’t loaded before it tries to play, is that right? How can I check to see if the file is loaded before playing?
Here is my code:
function playMusic1(evt:MouseEvent):void{
channel.stop();
channel2.stop();
songPosition = 0;
var soundFile2:URLRequest = new URLRequest("http://r.jaxna.com/mp3Player/slushy.mp3");
myMusic2.load(soundFile2, myContext);
channel = myMusic.play(songPosition);
channel2 = myMusic2.play(songPosition);
}
function playMusic2(evt:MouseEvent):void {
channel.stop();
channel2.stop();
songPosition = 0;
var soundFile3:URLRequest = new URLRequest("http://r.jaxna.com/mp3Player/kingRight.mp3");
myMusic2.load(soundFile3, myContext);
channel = myMusic.play(songPosition);
channel2 = myMusic2.play(channel.position);
Sound files load asynchronously in Flash. Listen for the Event.COMPLETE event and in that event handler, add code to check if both are loaded and then play.
an example: