View comments | RSS feed

get (Microphone.get method)

public static get([index:Number]) : Microphone

Returns a reference to a Microphone object for capturing audio. To actually begin capturing the audio, you must attach the Microphone object to a MovieClip object (see MovieClip.attachAudio()).

Unlike objects that you create using the new constructor, multiple calls to Microphone.get() reference the same microphone. Thus, if your script contains the lines mic1 = Microphone.get() and mic2 = Microphone.get(), both mic1 and mic2 reference the same (default) microphone.

In general, you shouldn't pass a value for index; simply use the Microphone.get() method to return a reference to the default microphone. By means of the Microphone settings panel (discussed later in this section), the user can specify the default microphone Flash should use. If you pass a value for index, you might be trying to reference a microphone other than the one the user prefers. You might use index in rare cases--for example, if your application is capturing audio from two microphones at the same time.

When a SWF file tries to access the microphone returned by the Microphone.get() method--for example, when you issue MovieClip.attachAudio()--Flash Player displays a Privacy dialog box that lets the user choose whether to allow or deny access to the microphone. (Make sure your Stage size is at least 215 x 138 pixels; this is the minimum size Flash requires to display the dialog box.)

When the user responds to this dialog box, the Microphone.onStatus event handler returns an information object that indicates the user's response. To determine whether the user has denied or allowed access to the camera without processing this event handler, use Microphone.muted.

The user can also specify permanent privacy settings for a particular domain by right-clicking (Windows) or Control-clicking (Macintosh) while a SWF file is playing, choosing Settings, opening the Privacy panel, and selecting Remember.

You can't use ActionScript to set the Allow or Deny value for a user, but you can display the Privacy panel for the user by using System.showSettings(0). If the user selects Remember, Flash Player no longer displays the Privacy dialog box for SWF files from this domain.

If Microphone.get() returns null, either the microphone is in use by another application, or there are no microphones installed on the system. To determine whether any microphones are installed, use Microphone.names.length [fixed typo 10/11/2007]. To display the Flash Player Microphone Settings panel, which lets the user choose the microphone to be referenced by Microphone.get(), use System.showSettings(2).

Availability: ActionScript 1.0; Flash Player 6 - Note: The correct syntax is Microphone.get(). To assign the Microphone object to a variable, use syntax like active_mic = Microphone.get().

Parameters

index:Number [optional] - A zero-based integer that specifies which microphone to get, as determined from the array that Microphone.names contains. To get the default microphone (which is recommended for most applications), omit this parameter.

Returns

Microphone -

Example

The following example lets the user specify the default microphone, and then captures audio and plays it back locally. To avoid feedback, you may want to test this code while wearing headphones.

this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth());
System.showSettings(2);
var active_mic:Microphone = Microphone.get();
sound_mc.attachAudio(active_mic);

The MovieClip.getNextHighestDepth() method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth() method.

See also

get (Microphone.get method), index (Microphone.index property), muted (Microphone.muted property), names (Microphone.names property), onStatus (Microphone.onStatus handler), attachAudio (MovieClip.attachAudio method), showSettings (System.showSettings method)


Flash CS3


Comments


flashizzle said on Oct 4, 2007 at 6:02 PM :
The above page references "Microphones.names.length". This is a typo.
There is no Microphones (plural) object. You should instead reference
"Microphone.names.length" (single) to determine how many mics are
available on a user's system.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00001866.html