In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Voice Recon Prototype

Get Adobe Flash player
by mash 26 Dec 2008
package {
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.media.*;
    import flash.system.*;
    import flash.text.*;
    import flash.utils.*;
    public class VoiceRecon extends Sprite {
        private var log_tf :TextField;
        private var nc :NetConnection;
        private var ns :NetStream;
        private var mic :Microphone;
        public function VoiceRecon() {
            log_tf = create_log_tf();
            addChild( log_tf );

            log("init");
            Security.loadPolicyFile("");
  
            mic = Microphone.getMicrophone();

            nc = new NetConnection;
            nc.addEventListener( NetStatusEvent.NET_STATUS, function(e :NetStatusEvent) :void {
                log(e.info.code);

                if ( e.info.code=="NetConnection.Connect.Success" ) {
                    ns = new NetStream(nc);
                    ns.addEventListener( NetStatusEvent.NET_STATUS, arguments.callee );
                    start_recording();
                }
            });
            nc.connect('');
        }
        private function start_recording() :void {
          ns.attachAudio( mic );
          ns.publish("test","record");
          setTimeout( function() :void {
            // call api
            log("[call api]");
            var loader :URLLoader = new URLLoader;
            var url :String = "";
            loader.load( new URLRequest(url) );
            loader.addEventListener( Event.COMPLETE, oncomplete );
          },5000 );      
   
        }

        private function oncomplete(e :Event) :void {
            var loader:URLLoader = URLLoader(e.target);
            log("result: "+loader.data);

            ns.attachAudio(null);
            ns.close();
        }

        private function log(text :String) :void {
            log_tf.appendText(text + "\n");
        }
        private function create_log_tf() :TextField {
            log_tf = new TextField;
            log_tf.type = TextFieldType.INPUT;
            log_tf.width = 1000;
            log_tf.height = 1000;
            log_tf.y     = 100;
            return log_tf;
        }
    }
}