You Are Here Home > How to show a microphone activity indicator in Actionscript...

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 min:Microphone = new Microphone();
var micActivityIndicator:Shape = new Shape();
function ShowMicActivity(e:TimerEvent):void {
             var h:int = 0;
             var y:int = 0;
	if (mic.activityLevel > 0) {
		h = mic.activityLevel;
		y = 150 - mic.activityLevel;
	} else {
		h = 5;
		y = 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.

How to show a microphone activity indicator in Actionscript 3
Filed under: Actionscript,Flash   Posted by: Hamid

7 Comments »

  1. luke:
     

    you haven’t defined the microphone in this code.

    var mic:Microphone=new Microphone();

    you also have a duplicate variable definition by defining h and y twice.

    helpful code as starting point but might want to check for errors before sharing… :-)

    Comment

     
  2. admin:
     

    Hey, thanks, but this code was meant to be exactly a starting point and I kind of assumed that whoever is looking for this, knows that the mic needs to be defined…

    I fixed up the code to prevent any future confusion.

    Thanks again :)

    Comment

     
  3.  

    Thanks, this is an interesting script.

    Comment

     
  4. g:
     

    Also, you need to add

    micTimer.start();

    and

    addChild(micActivityIndicator);

    Comment

     
  5. Shippy:
     

    You can’t do that:
    var min:Microphone = new Microphone();

    Instead use this:
    var min:Microphone = Microphone.getMicrophone();

    (See the Actionscript 3 reference)

    Comment

     
  6. M:
     

    Thank you very much. This is exactly what I was looking for.

    Comment

     
  7. vinay:
     

    Thanks man! I got what i want. :)

    Comment

     

RSS feed for comments on this post. TrackBack URL

Leave a comment