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:未找到类型或不是编译-时间常数:事件。”
谁能告诉我我做错了什么?
谢谢。
Any help would be greatly appreciated.
I'm loading a sound like this:
var mySound:Sound = new Sound();
mySound.load(new URLRequest("audio/filename.mp3"));
mySoundChannel:SoundChannel = mySound.play();
Then I'm adding a listener and trying to call a function with the SOUND_COMPLETE event, like this:
mySoundChannel.addEventListener(Event.SOUND_COMPLETE,audioComplete);
function audioComplete(Event:Event){
trace("done!");
}
However, I keep getting this error: "1046:Type was not found or was not a compile-time constant:Event."
Can anyone give me a hint as to what I'm doing wrong?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
更改
为
AS 区分大小写。
事件
与事件
不同。Event
是一个类的名称。event
是您分配给Event
类型的局部变量的名称。此外,声音是异步加载到 Flash 中的。这意味着当您调用
sound.load()
时,Flash Player 将开始在新线程上加载声音,并在加载声音时继续执行下一行代码。当声音完全加载时,Event.COMPLETE
事件被触发,NOT 当声音播放完毕时被触发。要在声音播放完毕时触发函数,请使用
setTimeout
Change
to
AS is case sensitive.
event
is not the same asEvent
.Event
is the name of a class.event
is the name you are assigning to the local variable of the typeEvent
Moreover, sound is loaded in Flash asynchronously. This means that when you call
sound.load()
, Flash Player will start loading the sound on a new thread and continue the next lines of code while the sound is loading. TheEvent.COMPLETE
event is triggered when this sound is fully loaded, NOT when the sound has finished playing.to trigger a function when a sound has finished playing, use
setTimeout
尝试将
function audioComplete(Event:Event){
更改为
function audioComplete(e:Event){
最好不要使用类名称作为变量名称。它可能会让试图阅读代码的编译器和程序员感到困惑。
Try changing
function audioComplete(Event:Event){
to
function audioComplete(e:Event){
It's a good idea to not use class names for your variable names. It can confuse the compiler and programmers trying to read the code.
导入事件类:
导入 flash.events.Event
Import the Event class:
import flash.events.Event
感谢各位的回复。我最终找到了一种更好的方法来做到这一点。如果有人遇到同样的问题,这对我有用:
Thanks to those of you who responded. I ended up finding a better way to do this. If anyone runs into the same problem, here is what is working for me: