Flash CS3 Documentation |
|||
| Programming ActionScript 3.0 > Working with sound > Capturing sound input > Accessing a microphone | |||
The Microphone class does not have a constructor method. Instead, you use the static Microphone.getMicrophone() method to obtain a new Microphone instance, as shown below:
var mic:Microphone = Microphone.getMicrophone();
Calling the Microphone.getMicrophone() method without a parameter returns the first sound input device discovered on the user's system.
A system can have more than one sound input device attached to it. Your application can use the Microphone.names property to get an array of the names of all available sound input devices. Then it can call the Microphone.getMicrophone() method with an index parameter that matches the index value of a device's name in the array.
A system might not have a microphone or other sound input device attached to it. You can use the Microphone.names property or the Microphone.getMicrophone() method to check whether the user has a sound input device installed. If the user doesn't have a sound input device installed, the names array has a length of zero, and the getMicrophone() method returns a value of null.
When your application calls the Microphone.getMicrophone() method, Flash Player displays the Flash Player Settings dialog box, which prompts the user to either allow or deny Flash Player access to the camera and microphone on the system. After the user clicks on either the Allow button or the Deny button in this dialog, a StatusEvent is dispatched. The code property of that StatusEvent instance indicates whether microphone access was allowed or denied, as shown in this example: <updated code Oct. 11, 2007>
import flash.media.Microphone;
var mic:Microphone = Microphone.getMicrophone();
mic.addEventListener(StatusEvent.STATUS, this.onMicStatus);
function onMicStatus(event:StatusEvent):void
{
if (event.code == "Microphone.Unmuted")
{
trace("Microphone access was allowed.");
}
else if (event.code == "Microphone.Muted")
{
trace("Microphone access was denied.");
}
}
The StatusEvent.code property will contain "Microphone.Unmuted" if access was allowed, or "Microphone.Muted" if access was denied.
|
NOTE |
|
The |
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000298.html