package
{
import flash.display.Sprite;
import flash.media.Video;
import flash.media.Camera;
import flash.events.Event;
import flash.events.ActivityEvent;
import flash.text.TextField;
public class Main extends Sprite
{
private var cam:Camera;
private var vid:Video;
private var hasCamera:Boolean = true;
private var text:TextField;
public function Main ()
{
cam = flash.media.Camera.getCamera();
vid = new Video();
vid.attachCamera(cam);
addChild(vid);
cam.setMotionLevel(20);
this.addEventListener("enterFrame", enterFrame);
cam.addEventListener(ActivityEvent.ACTIVITY, active);
text = new TextField();
addChild(text);
text.x = 300;
}
private function active(evt:ActivityEvent):void
{
trace(cam.activityLevel + " " + cam.motionLevel + " " + cam.name);
}
private function enterFrame(event:Event):void
{
if(cam.activityLevel < 10)
{
text.text = "No activity detected";
}
if(cam.activityLevel > 12)
{
text.text = "Motion!";
}
}
}
}
|