Spectrum Analyzer

This seems to be everyone’s first AS3 endeavor (sorta like Pong is everyone’s first game), but oh well… gotta keep up with the joneses’s…

[AS]package {
import flash.display.Shape;
import flash.display.Sprite;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.utils.ByteArray;
import flash.net.URLRequest;
import flash.events.;
import flash.geom.
;

public class SpecAnny extends Sprite{
private var _barArray:Array;
private var _sound:Sound;
private var _sc:SoundChannel;
private var _ba:ByteArray;
private var _numBars:int;

public function SpecAnny(){
_barArray = new Array();
_sound = new Sound();
_sc = new SoundChannel();
_ba = new ByteArray();
_numBars = 8;

stage.frameRate=31;
initDisplay();

function initDisplay():void{
for (var i:int = 0; i < _numBars; i++){
var bar:Shape = new Shape();
var mat = new Matrix();
mat.createGradientBox(5, -75, 90*(Math.PI/180));
bar.graphics.beginGradientFill(“linear”, [0x00FF00, 0x990000], [100, 100], [0, 255], mat);
bar.graphics.drawRect(0, 0, 5, -75);
bar.y = bar.height+50;
bar.x = 50 + i*8;
addChild(bar);
_barArray.push(bar);
}
startSound();
}

function startSound():void{
_sound.load(new URLRequest(“my.mp3”));
_sc = _sound.play(0, 25);
var enterFrameController:Sprite = new Sprite();
enterFrameController.addEventListener (Event.ENTER_FRAME, animate);
}

function animate():void{
var yscale:Number = 0;
SoundMixer.computeSpectrum (_ba, true, 0);
for (var i:int = 0; i < _numBars; i++){
yscale = _ba.readFloat();
_barArray*.scaleY = yscale;
}
}
}
}
}[/AS]

example: http://www.onebyonedesign.com/flash/specAnny/