无限循环声音

import flash.net.URLRequest;
import flash.media.Sound;
import flash.events.Event;

var req:URLRequest = new URLRequest("filename.mp3"); 
var snd:Sound = new Sound(req);

snd.addEventListener(Event.COMPLETE, function(e: Event)
{
    snd.play(0, int.MAX_VALUE); // There is no way to put "infinite"
}

在调用 play() 函数之前,你也无需等待声音加载。所以这将做同样的工作:

snd = new Sound(new URLRequest("filename.mp3"));
snd.play(0, int.MAX_VALUE);

如果你真的想出于某种原因无限时间循环声音(int.MAX_VALUE 会循环播放声音大约 68 年,不计算 mp3 导致的暂停……)你可以这样写:

var st:SoundChannel = snd.play();
st.addEventListener(Event.SOUND_COMPLETE, repeat);
function repeat(e:Event) { 
    st.removeEventListener(Event.SOUND_COMPLETE, repeat);
    (st = snd.play()).addEventListener(Event.SOUND_COMPLETE, repeat);
}

play() 函数每次调用时都会返回 SoundChannel 对象的新实例。我们将它变为变量并监听其 SOUND_COMPLETE 事件。在事件回调中,将从当前 SoundChannel 对象中删除侦听器,并为新的 SoundChannel 对象创建新侦听器。