艺虎动画 > 在Flash Player里播放声音的两种方法 flash中声音问题设置

在Flash Player里播放声音的两种方法 flash中声音问题设置

翼虎动漫   2010-8-5

 

 

 

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();