RecordMicrophone_Example.as 1.43 KB
Newer Older
O'Reilly Media, Inc's avatar
O'Reilly Media, Inc committed
1
package {
	
	import flash.display.MovieClip;
	import flash.media.Microphone;
	import flash.events.MouseEvent;
	import com.learningactionscript3.ui.RoundRectButton;
	import com.learningactionscript3.sound.RecordMicrophone;
	
	public class RecordMicrophone_Example extends MovieClip {
		
		private var _sm:RecordMicrophone;
		private var _mic:Microphone;
		
		public function RecordMicrophone_Example() {
			_sm = new RecordMicrophone();
			
			createButton(25, "Record", startRecording);
			createButton(50, "Stop Recording", stopRecording);
			createButton(75, "Play", playRecording);
			createButton(100, "Stop Playing", stopPlaying);
			createButton(125, "Save Recording", saveRecording);
		}
		
		private function createButton(yLoc:Number, labl:String, 
									  func:Function):void {
			var btn:RoundRectButton = 
			    new RoundRectButton(120, 20, 10, 2, 0x000099, 
									labl, 0xFFFFFF);
			btn.x = 20;
			btn.y = yLoc;
			btn.addEventListener(MouseEvent.CLICK, func, 
								 false, 0, true);
			addChild(btn);
		}
		
		private function startRecording(evt:MouseEvent):void {
			_sm.startRecording();
		}
		
		private function stopRecording(evt:MouseEvent):void {
			_sm.stopRecording();
		}
		
		private function playRecording(evt:MouseEvent):void {
			_sm.playSound();
		}
		
		private function stopPlaying(evt:MouseEvent):void {
			_sm.stopPlaying();
		}
		
		private function saveRecording(evt:MouseEvent):void {
			_sm.saveFile();
		}
		
	}
	}