package { import flash.display.BitmapData; import flash.display.Sprite; import flash.display.StageQuality; import flash.events.Event; import flash.media.Camera; import flash.media.Video; import org.libspark.lcdbitmap.LCDBitmap; [SWF(width = 465, height = 465, backgroundColor = 0x000000, frameRate = 30)] public class VideoSample extends Sprite { private static const SOURCE_VIDEO_WIDTH:uint = 60; private static const SOURCE_VIDEO_HEIGHT:uint = 45; public function VideoSample() { setupStage(); if (setupVideo()) { setupLCDBitmap(); } } private var _video:Video; private var _videoBitmapData:BitmapData; private function setupStage():void { stage.quality = StageQuality.LOW; } private function setupVideo():Boolean { var camera:Camera = Camera.getCamera(); if (camera == null) { return false; } _video = new Video(SOURCE_VIDEO_WIDTH, SOURCE_VIDEO_HEIGHT); _video.attachCamera(camera); _videoBitmapData = new BitmapData(_video.width, _video.height, false, 0x000000); addEventListener(Event.ENTER_FRAME, videoEnterFrameHandler); return true; } private function videoEnterFrameHandler(e:Event):void { _videoBitmapData.fillRect(_videoBitmapData.rect, 0x000000); _videoBitmapData.draw(_video); } private function setupLCDBitmap():void { var lcd:LCDBitmap = new LCDBitmap(_videoBitmapData); lcd.x = Math.floor((stage.stageWidth - lcd.width) / 2); lcd.y = Math.floor((stage.stageHeight - lcd.height) / 2); addChild(lcd); } } }