本文推荐在Flash文档中嵌入音频文件的两种要领,使其能够在Flash Player中正常播放。
1、建立 Sound 对象用 load() 要领加载外部的 MP3 来播放;
2、让 Sound 对象监听 sampleData 事件,这样能够播放由程序动态生成的声音,比方:
下面的示例播放基本的正弦波。
以下是引用片段:
var mySound:Sound = new Sound();
function sineWaveGenerator(event:SampleDataEvent):void {
for ( var c:int=0; c<8192; c++ ) {
event.data.writeFloat(math.sin((Number(c+event.position)/Math.PI/2))*0.25);
event.data.writeFloat(Math.sin((Number(c+event.position)/Math.PI/2))*0.25);
}
}
mySound.addEventListener(Event.SAMPLE_DATA,sineWaveGenerator);
mySound.play();