This compiles for me:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300"> <mx:Script> <![CDATA[ import flash.media.Microphone; import flash.events.ActivityEvent; import flash.events.Event; import flash.events.StatusEvent; public var mic:Microphone = Microphone.getMicrophone(); // <--- gives the error ]]> </mx:Script> <mx:VBox> </mx:VBox> </mx:Application> You didn't happen to name your mxml file "mic" or "Microphone" did you? ________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Amy Sent: Thursday, July 31, 2008 8:30 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Flex3 cookbook error in microphone example: constructor functions must be instance methods --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "Jo Morano" <[EMAIL PROTECTED]> wrote: > > Moving the script up to the application level didn't help. I've put the code > from the book which should just compile (using an app now and moving vbox > below): > > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> " width="400" > height="300" creationComplete="createMic()"> > <mx:Script> > <![CDATA[ > import flash.media.Microphone; > import flash.events.ActivityEvent; > import flash.events.Event; > import flash.events.StatusEvent; > > public var mic:Microphone;// = Microphone.getMicrophone (); // <--- It seems to me that you've commented out the part that would prevent the error. Here's the example from the Help: package { import flash.display.Sprite; import flash.events.*; import flash.media.Microphone; import flash.system.Security; import flash.system.SecurityPanel; public class MicrophoneExample extends Sprite { public function MicrophoneExample() { var mic:Microphone = Microphone.getMicrophone(); Security.showSettings(SecurityPanel.MICROPHONE); mic.setLoopBack(true); if (mic != null) { mic.setUseEchoSuppression(true); mic.addEventListener(ActivityEvent.ACTIVITY, activityHandler); mic.addEventListener(StatusEvent.STATUS, statusHandler); } } private function activityHandler(event:ActivityEvent):void { trace("activityHandler: " + event); } private function statusHandler(event:StatusEvent):void { trace("statusHandler: " + event); } } } It looks like Microphone might be a Singleton Class and probably you can't even refer to it without using getMicrophone() to get the instance of it. HTH; Amy