Flash AS3-2037错误

Flash AS3-2037错误,flash,actionscript-3,actionscript,Flash,Actionscript 3,Actionscript,我的AS3项目中有两个按钮,可以加载.mp3文件,然后播放它们。我有两个按钮,可以在不工作的文件之间切换。我得到一个错误,说: 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::MainTi

我的AS3项目中有两个按钮,可以加载.mp3文件,然后播放它们。我有两个按钮,可以在不工作的文件之间切换。我得到一个错误,说:

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()
我想这意味着文件在尝试播放之前没有加载,是吗?如何在播放前检查文件是否已加载

这是我的密码:

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);

声音文件在Flash中异步加载。侦听Event.COMPLETE事件,并在该事件处理程序中添加代码以检查两者是否都已加载,然后播放

例如:

//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);
}

声音文件在Flash中异步加载。侦听Event.COMPLETE事件,并在该事件处理程序中添加代码以检查两者是否都已加载,然后播放

例如:

//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);
}

看起来您使用相同的
声音
对象加载另一个声音文件。文档明确指出,您不能重复使用以前加载的声音对象来加载另一个声音文件(请参见
load
函数),每次要加载和播放不同的声音时,您必须创建一个
new sound()
对象。加载后,您可以任意多次播放该声音,并从声音中的任何点开始播放


如果只播放这些特定的声音文件,可以创建两个声音对象并预加载它们

看起来您使用相同的
声音
对象加载另一个声音文件。文档明确指出,您不能重复使用以前加载的声音对象来加载另一个声音文件(请参见
load
函数),每次要加载和播放不同的声音时,您必须创建一个
new sound()
对象。加载后,您可以任意多次播放该声音,并从声音中的任何点开始播放

如果只播放这些特定的声音文件,可以创建两个声音对象并预加载它们