actionscript-3 - AS3在第一个音频文件完成播放后播放第二个音频文件

任何帮助将不胜感激。

我正在加载这样的声音:

var mySound:Sound = new Sound();
mySound.load(new URLRequest("audio/filename.mp3"));
mySoundChannel:SoundChannel = mySound.play();

然后,我添加一个侦听器,并尝试使用SOUND_COMPLETE事件调用一个函数,如下所示:
mySoundChannel.addEventListener(Event.SOUND_COMPLETE,audioComplete);
function audioComplete(Event:Event){
trace("done!");
}

但是,我不断收到此错误:“找不到1046:Type或不是编译时常量:Event。”

谁能给我提示我做错了什么?

谢谢。

最佳答案

更改

function audioComplete(Event:Event){


function audioComplete(event:Event){

AS区分大小写。 eventEvent不同。 Event是类的名称。 event是您分配给Event类型的本地变量的名称

此外,声音会异步加载到Flash中。这意味着,当您调用sound.load()时,Flash Player将开始在新线程上加载声音,并在加载声音时继续下一行代码。声音完全加载时,将触发Event.COMPLETE事件,声音播放完毕后,将触发 NOT

要在声音播放完毕后触发功能,请使用setTimeout
var mySound:Sound = new Sound();
mySound.load(new URLRequest("audio/filename.mp3"));
mySound.addEventListener(Event.COMPLETE, soundLoaded);

function soundLoaded(e:Event):void {
    mySound.play();
    setTimeout(audioComplete, mySound.length);
}
function audioComplete(){
    trace("done!");
}

https://stackoverflow.com/questions/7773581/

相关文章:

spring - 哪个工具可以验证 Spring 配置

installation - 编译后ISTool错误

python - 安装Python库时出错?

compiler-errors - mingw提供错误-C编译器无法创建可执行文件

visual-studio-2008 - midl : error MIDL9008

msbuild - MSbuild 4.0无法编译.Net 3.5项目

ruby - 无法安装rmagick

eclipse - 在Eclipse/STS中进行编译不会产生任何输出

python - Mac OS X中的python错误 undefined symbol : “_P

.net - Visual Studio Web引用错误