2007/07/13 | 一个简单的音波分析器
类别(做生活) | 评论(9) | 阅读(304) | 发表于 12:11

例子如下:

代码如下:
package {
  import flash.display.Sprite;
  import flash.media.Sound;
  import flash.media.SoundMixer;
  import flash.utils.ByteArray;
  import flash.events.Event;
  import flash.net.URLRequest;  
  public class wave extends Sprite {
    var sd:Sound = new Sound();
    var ba:ByteArray = new ByteArray();
    public function wave() {
      sd.load(new URLRequest("05.mp3"));
      sd.play(0,1000);        
      for (var i:int=0; i <= 255; i++) {
        var _circle:Sprite = new Sprite();
        _circle.graphics.beginFill(0xffffff*i);
        _circle.graphics.drawCircle(0,0,1);
        _circle.graphics.endFill();
        _circle.x=72 + i;
        _circle.y=150;
        this.addChild(_circle);
      }   
      addEventListener(Event.ENTER_FRAME,onEnterFrame);
    }
    private function onEnterFrame(event:Event):void {
      SoundMixer.computeSpectrum(ba,true,0);
      for (var i:int=0; i < 255; i++) {
        this.getChildAt(i).scaleY=3+ba.readFloat()*150;
      }
    }
  }
}

0

评论Comments

日志分类
首页[67]
说故事[8]
看世界[15]
冶情操[9]
贴图片[15]
做生活[20]