topical media & game development

talk show tell print

lib-flex-animation-code-05-CameraBitmap.ax

lib-flex-animation-code-05-CameraBitmap.ax (swf ) [ flash ] flex


  package {
      import flash.display.Bitmap;
      import flash.display.BitmapData;
      import flash.display.Sprite;
      import flash.display.StageAlign;
      import flash.display.StageScaleMode;
      import flash.events.Event;
      import flash.geom.Matrix;
      import flash.media.Camera;
      import flash.media.Video;
  
      public class @ax-lib-flex-animation-code-05-CameraBitmap extends Sprite
      {
          private var _cam:Camera;
          private var _vid:Video;
          private var _bmpd:BitmapData;
          
          public function @ax-lib-flex-animation-code-05-CameraBitmap()
          {
              stage.align = StageAlign.TOP_LEFT;
              stage.scaleMode = StageScaleMode.NO_SCALE;
              
              _cam = Camera.getCamera();
              _cam.setMode(320, 240, 15);
              _vid = new Video(320, 240);
              _vid.attachCamera(_cam);
              
              _bmpd = new BitmapData(320, 240, false);
              addChild(new Bitmap(_bmpd));
              
              addEventListener(Event.ENTER_FRAME, onEnterFrame);
          }
          
          private function onEnterFrame(event:Event):void
          {
              _bmpd.draw(_vid, new Matrix(-1, 0, 0, 1, _bmpd.width, 0));
          }
      }
  }


(C) Æliens 18/6/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.