外部mp3完全加载时进行Flash检查

时间:2011-08-23 15:30:54

标签: flash actionscript-3

我从外部网址加载了一些MP3。 我需要等待完全加载mp3,然后开始播放它。 你知道我怎么能检查mp3何时完全加载?

这是我的代码:

var s:Sound = new Sound(new URLRequest("url.com/file.mp3"));  
var channel:SoundChannel = new SoundChannel();
channel = s.play();

Best,Flavio

1 个答案:

答案 0 :(得分:0)

在调用play之前,您可以监听声音对象的完整事件。此外,由于Sound.play()返回一个SoundChannel对象,您不需要实例化它,只需定义一个变量以将其引用保存在完整处理程序的范围之外。

var channel:SoundChannel;
var s:Sound = new Sound(new URLRequest("url.com/file.mp3")); 
s.addEventListener(Event.COMPLETE,onSoundLoaded);

function onSoundLoaded(evt:Event):void
{
    s.removeEventListener(Event.COMPLETE,onSoundLoaded);
    channel = s.play();
}