In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

iTunes Visualizer for wonderfl

download : http://mizt.org/wonderfl
required : Mac OS X 10.7 &  iTunes 10.4+
license : non-comacial use only, absolutely no warranty
Get Adobe Flash player
by mizt 19 Nov 2011
// download : http://mizt.org/wonderfl
// required : Mac OS X 10.7 & iTunes 10.4+
// license : non-comacial use only, absolutely no warranty
package {
    import flash.display.*;  
    import flash.events.*; 
    import flash.system.*;
    import flash.external.ExternalInterface;
    import net.hires.debug.Stats;
    [SWF(width="900", height="600", backgroundColor="#0", frameRate="30")]
    public class Main extends Sprite {
        
        // callback from iTunes plug-in
        private var waveformL:Array = new Array(512); // -1. to 1.
        private var waveformR:Array = new Array(512); // -1. to 1.
        private var spectrumL:Array = new Array(256); // 0. to 1.
        private var spectrumR:Array = new Array(256); // 0. to 1.
        
        public function audioReceived($data:Array):void {
            var k:int=0;
            for(k=0; k<512; k++) {
                waveformL[k] = Number($data[k]);
                waveformR[k] = Number($data[k+512]);
            }
            for(k=0; k<256; k++) {
                spectrumL[k] = Number($data[k+512+512]);
                spectrumR[k] = Number($data[k+512+512+256]);
            }
        }
        // initialize from iTunes plug-in
        public function setup():void {
            this.addEventListener(Event.ENTER_FRAME,draw);
        }
        
        public function Main() {
           
            Security.allowDomain("*");
            
            stage.scaleMode = "noScale";
            stage.align = "TL";
            stage.quality = "LOW";
            
            // initialize array
            var k:int=0;
            for(k=0; k<512; k++) waveformL[k] = 0, waveformR[k] = 0;
            for(k=0; k<256; k++) spectrumL[k] = 1, spectrumR[k] = 1;
            
            ExternalInterface.addCallback("audioReceived",this.audioReceived);
            ExternalInterface.addCallback("setup",this.setup);
            ExternalInterface.call("register");
            
            addChild(new Stats());
        }
        
        
        private function draw(e:Event):void {
            
            // insert your code here ... 
            
            
            // example
            var g:Graphics = this.graphics;
            g.clear();
            
            var w:int = stage.stageWidth;
            var h:int = stage.stageHeight-1;
            var w1:Number = w/512.;
            var w2:Number = w/256.;
            
            g.lineStyle(0,0xFFFFFF);
            
            var k:int=0;
            for(k=0; k<512; k++) {
                var v1:Number = h*(waveformL[k]+1.0)*0.125;
                var v2:Number = h*(0.25+(waveformR[k]+1.0)*0.125);
                g.moveTo(w1*k,v1),g.lineTo(w1*(k+1),v1);
                g.moveTo(w1*k,v2),g.lineTo(w1*(k+1),v2);
            }
            for(k=0; k<256; k++) {
                var v3:Number = h*(0.50+(spectrumL[k])*0.25);
                var v4:Number = h*(0.75+(spectrumR[k])*0.25);
                g.moveTo(w2*k,v3),g.lineTo(w2*(k+1),v3);
                g.moveTo(w2*k,v4),g.lineTo(w2*(k+1),v4);
            }
        }
    }
};