Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash 如何在Actionscript中播放短嘟嘟声?_Flash_Audio_Actionscript_Beep - Fatal编程技术网

Flash 如何在Actionscript中播放短嘟嘟声?

Flash 如何在Actionscript中播放短嘟嘟声?,flash,audio,actionscript,beep,Flash,Audio,Actionscript,Beep,我可以播放如下的哔哔声: private var beep:Sound = new Sound(); private function beepInit():void { var beepHandler:Function = new Function(); beepHandler = function(event:SampleDataEvent):void { for (var i:uint = 0; i < 2048; i++) {

我可以播放如下的哔哔声:

private var beep:Sound = new Sound();

private function beepInit():void {
    var beepHandler:Function = new Function();

        beepHandler = function(event:SampleDataEvent):void {
            for (var i:uint = 0; i < 2048; i++) {
                var wavePos:Number = 20 * Math.PI * i / 2048;
                event.data.writeFloat(Math.sin(wavePos));
                event.data.writeFloat(Math.sin(wavePos));
            }
        }

        beep.addEventListener(SampleDataEvent.SAMPLE_DATA, beepHandler);
}
private-var-beep:Sound=new-Sound();
私有函数beepInit():void{
var beepHandler:Function=new Function();
beepHandler=函数(事件:SampleDataEvent):无效{
对于(变量i:uint=0;i<2048;i++){
var wavePos:Number=20*Math.PI*i/2048;
event.data.writeFloat(Math.sin(wavePos));
event.data.writeFloat(Math.sin(wavePos));
}
}
beep.addEventListener(SampleDataEvent.SAMPLE_数据,beepHandler);
}
在应用程序启动时,我调用beepInit()

要播放,请调用:beep.play()


这是连续的声音。如何将其设置为500毫秒短蜂鸣声?

一旦达到要播放的长度,您需要停止创建样本。您可以通过检查创建的样本量与要播放的样本量来完成此操作

要播放的采样量是采样频率(44100/秒)乘以要播放的声音长度(以秒为单位)

private const采样频率:uint=44100;
创建的私有变量样本:uint=0;
私有变量长度秒:数字=0.5;
private-var-beep:Sound=new-Sound();
私有函数beepInit():void{
变量beepHandler:Function=Function(事件:SampleDataEvent):void{
对于(变量i:uint=0;i<2048;i++){
if(创建的样本>=样本频率*长度秒){
返回;
}
var wavePos:Number=20*Math.PI*i/2048;
event.data.writeFloat(Math.sin(wavePos));
event.data.writeFloat(Math.sin(wavePos));
samplesCreated++;
}
};
beep.addEventListener(SampleDataEvent.SAMPLE_数据,beepHandler);
}
private const sampleFrequency:uint = 44100;
private var samplesCreated:uint = 0;
private var lengthInSeconds:Number = 0.5;
private var beep:Sound = new Sound();

private function beepInit():void {
  var beepHandler:Function = function ( event:SampleDataEvent ):void {
    for (var i:uint = 0; i < 2048; i++) {
      if (samplesCreated >= sampleFrequency * lengthInSeconds) {
        return;
      }
      var wavePos:Number = 20 * Math.PI * i / 2048;
      event.data.writeFloat( Math.sin( wavePos ) );
      event.data.writeFloat( Math.sin( wavePos ) );
      samplesCreated++;
    }
  };

  beep.addEventListener( SampleDataEvent.SAMPLE_DATA, beepHandler );
}