How to show a microphone activity indicator in Actionscript 3

Here is what I did, first setup a timer:

var micDelay:uint	= 100;
var micRepeat:uint	= 0; /* Run forever */
var micTimer:Timer = new Timer(micDelay, micRepeat);

And then tell it to call our function every 100 milliseconds:

micTimer.addEventListener(TimerEvent.TIMER, ShowMicActivity);

Then the function:

var micActivityIndicator:Shape = new Shape();
function ShowMicActivity(e:TimerEvent):void {
	if (mic.activityLevel > 0) {
		var h:int = mic.activityLevel;
		var y:int = 150 - mic.activityLevel;
	} else {
		var h:int = 5;
		var y:int = 150 - 5;
	}
	micActivityIndicator.graphics.clear();
	micActivityIndicator.graphics.beginFill(0x000000);
	micActivityIndicator.graphics.drawRect(0, y, 10, h);
	micActivityIndicator.graphics.endFill();
}

I hope this helps someone, I couldn’t find anything online.

Leave a Comment for How to show a microphone activity indicator in Actionscript 3