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.
I'm the co-founder of
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
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
Thanks, this is an interesting script.
Comment
Also, you need to add
micTimer.start();
and
addChild(micActivityIndicator);
Comment
You can’t do that:
var min:Microphone = new Microphone();
Instead use this:
var min:Microphone = Microphone.getMicrophone();
(See the Actionscript 3 reference)
Comment
Thank you very much. This is exactly what I was looking for.
Comment
Thanks man! I got what i want.
Comment