package { import flash.display.Sprite; import flash.media.Camera; import flash.media.Video; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.utils.Timer; import flash.events.TimerEvent; import flash.events.ActivityEvent; public class main extends Sprite { private var myTextField:TextField; private var cam:Camera; private var t:Timer = new Timer(1000); public function main() { myTextField = new TextField(); myTextField.background = true; myTextField.selectable = false; myTextField.autoSize = TextFieldAutoSize.LEFT; cam = Camera.getCamera(); if (!cam) { myTextField.text = "No camera is installed."; }else { myTextField.text = "Waiting to connect."; connectCamera(); } addChild(myTextField); t.addEventListener(TimerEvent.TIMER, timerHandler); } private function connectCamera():void { var vid:Video = new Video(cam.width, cam.height); vid.x = 10; vid.y = 10; vid.attachCamera(cam); addChild(vid); cam.setMotionLevel(5, 1000); cam.addEventListener(ActivityEvent.ACTIVITY, activityHandler); } private function activityHandler(e:ActivityEvent):void { if (e.activating == true) { t.start(); } else { myTextField.text = "Everything is quiet."; t.stop(); } } private function timerHandler(event:TimerEvent):void { myTextField.x = 10; myTextField.y = cam.height + 20; myTextField.text = "There is some activity. Level: " + cam.activityLevel; } } }