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

Sound visual sample from Microphone

Get Adobe Flash player
by J2kawa 17 Jun 2009
/**
 * Copyright J2kawa ( http://wonderfl.net/user/J2kawa )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/sAHx
 */

package {
    import flash.display.*;
    import flash.media.*;
    import flash.utils.*;
    import flash.events.*;
    
    public class SoundVisual1 extends Sprite {
        private var mic:Microphone;
        private var canvas:Sprite;
        private var g:Graphics;
        private var timer:Timer;
        private var xPos:int=0;
        public function SoundVisual1() {
            mic = Microphone.getMicrophone();
            mic.setLoopBack(true);
	    mic.setUseEchoSuppression( true );
	    mic.gain = 50;
	    mic.rate = 11;
	    mic.setSilenceLevel( 5, 1000 );
            mic.soundTransform.volume=0;
            
            canvas = new Sprite( );
            g = canvas.graphics;
            g.clear();
            g.lineStyle(0,0x663300);
            g.moveTo(0,300);
            addChild(canvas);
            
            timer = new Timer(50);
            timer.addEventListener(TimerEvent.TIMER,drawSound);
            timer.start();
            
        }
        public function drawSound(evt:TimerEvent):void{
            g.lineTo(xPos,300 - mic.activityLevel);
            if(xPos>550){
                xPos=0;
                g.clear();
                g.lineStyle(0,0x663300);
                g.moveTo(0,300);
            }
            else{
                xPos++;
            }
        }
     }
}