开发者

AS3 - 2037 error

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 is开发者_开发问答n'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:

//Before you load,
myMusic2.addEventListener(Event.COMPLETE, musicLoaded);


//Event listener
private function musicLoaded(e:Event):void {
      //play logic here
      channel = myMusic.play(songPosition);
      channel2 = myMusic2.play(channel.position);
}


It looks like you using the same Sound object to load another sound file. The documentation explicitly states you can't reuse a previously loaded sound object to load another sound file (see the load function), you have to create a new Sound() object each time you want to load and play a different sound. Once loaded, you can play that sound as many times as you like and start playing from any point in the sound.

If you only ever going play just those specific sound files, you could create 2 sound objects and pre-load them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜