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

Mirror

Get Adobe Flash player
by keiso 12 Jan 2009
package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.StatusEvent;
	import flash.geom.Matrix;
	import flash.media.Camera;
	import flash.media.Video;

 	[SWF(width="465", height="465",backgroundColor="#000000",frameRate="30")]  

	public class Mirror extends Sprite
	{
		private	var vid:Video;
		private	var cam:Camera = Camera.getCamera();
		private	var myBitmapData:BitmapData;
		private	var mirrorMatrix:Matrix;
		
		public function Mirror()
		{
			
			if (cam == null) {
				trace("camera null");
			} else {
				cam.addEventListener(StatusEvent.STATUS, statusHandler);
				cam.setMode(465, 465, 30); 
				
				vid = new Video(465 , 465);
				vid.attachCamera(cam);
				vid.smoothing = true;
			}
			
		}
		private function statusHandler(event:StatusEvent):void {
			if (cam.muted) {
				trace("camera muted");
			} else {
				myBitmapData = new BitmapData(vid.width, vid.height);
			
				var myImage:Bitmap = new Bitmap(myBitmapData);
				addChild(myImage);
				mirrorMatrix = new Matrix(-1,0,0,1,myBitmapData.width);
			
				stage.addEventListener(Event.ENTER_FRAME, onEnterFrames);
			}
		}
		
		private function onEnterFrames(event:Event):void {
			myBitmapData.draw(vid,mirrorMatrix);
		}
		
	}
}