Main.mxml
Fx042.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="init(event)"
backgroundGradientColors="[#0E0E0E,#0E0E0E]" viewSourceURL="srcview/index.html">
<mx:VBox
width="100%"
horizontalAlign="left">
<mx:Button label="Load MP3" click="onClick(event)"/>
</mx:VBox>
<mx:VBox
width="100%"
height="100%"
horizontalAlign="center"
verticalAlign="middle">
<mx:Canvas id="_canvas"/>
</mx:VBox>
<mx:Script>
<![CDATA[
/**
* Requires the following sound library
* @see http://www.flexiblefactory.co.uk/flexible/?p=46
*/
import org.audiofx.mp3.MP3FileReferenceLoader;
import org.audiofx.mp3.MP3SoundEvent;
private const REF_RADIUS:Number = 200;
private var _channel:SoundChannel;
private var _mp3loader:MP3FileReferenceLoader;
private var _fr:FileReference;
private function init(e:Event):void{
_mp3loader = new MP3FileReferenceLoader();
_mp3loader.addEventListener(MP3SoundEvent.COMPLETE,onComplete);
_fr = new FileReference();
_fr.addEventListener(Event.SELECT,onSelect);
}
private function onClick(e:MouseEvent):void{
_fr.browse([new FileFilter("mp3 files","*.mp3")]);
}
private function onSelect(e:Event):void{
if (_channel != null){
_channel.stop();
}
_mp3loader.getSound(_fr);
}
private function onComplete(e:MP3SoundEvent):void{
_channel = e.sound.play(0,999);
this.addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
private function onEnterFrame(e:Event):void{
var g:Graphics = _canvas.graphics;
g.clear();
var ba:ByteArray = new ByteArray();
SoundMixer.computeSpectrum(ba);
var hemisphere:Array = new Array();
var otherHemisphere:Array = new Array();
for (var i:int=0; i<=0xFF; i++){
var theta:Number = Math.PI*i/0xFF;
var rad:Number = ba.readFloat()*REF_RADIUS;
var x1:Number = _canvas.width/2 + (REF_RADIUS + rad)*Math.cos(theta);
var y1:Number = _canvas.height/2 + (REF_RADIUS + rad)*Math.sin(theta);
hemisphere.push(new Point(x1,y1));
var x2:Number = _canvas.width/2 + (REF_RADIUS + rad)*Math.cos(-theta);
var y2:Number = _canvas.height/2 + (REF_RADIUS + rad)*Math.sin(-theta);
otherHemisphere.push(new Point(x2,y2));
}
draw(g,hemisphere,0x005885);
draw(g,otherHemisphere,0x005885);
}
private function draw(target:Graphics,points:Array,color:uint=0xFFFFFF):void{
target.beginFill(color);
for (var i:int=0; i<points.length; i++){
var p:Point = points[i];
if (i==0){
target.moveTo(p.x,p.y);
}
else{
target.lineTo(p.x,p.y);
}
}
target.endFill();
}
]]>
</mx:Script>
</mx:Application>
Powered by blog Boreal Kiss 2008.