AS: Main
I used alot from Macromedia LiveDocs
I will try and cover the camera object here, this allows you to intercept data from the user's webcam and could be a very sweet gimmick for your game ;)
So How Does it Work?
Flash has a built it "Camera" Object, we need to learn to manipulate it.
Locating the camera:
First of all we must attach the camera to an object so we can process it :
var cam:Camera= Camera.get();
note that Camera.get(); is what's needed rahter then a constructor (with new) since there is no data we need to create, the camera is already attached.
Camera.get() returns null if there is no camera available or the camera is undefined.
Now that we have defined the camera, it's time to
Set it's mode:
This is done by the setMode command, it sets the width, the height and the FPS your camera will capture (when possible)
setMode(width:Number, height:Number, fps:Number);
let's say I want my camera to capture 300*300 and have 12 fps, you can not exceed the max FPS of the users camera, so better be safe then sorry
can.setMode(300,300,12);
you can always find the current fps with cam.currentFps, and the fps it SHOULD capture in as can.fps.
now we should
set the quality of the picture
cam.setQuality(bandwidth:Number, frameQuality:Number)
we should never use too much bandwidth since it might trouble the user's computer,
examples:
// Ensure that no more than 8192 (8K/second) is used to send video
cam.setQuality(8192,0);
// Ensure that no more than 8192 (8K/second) is used to send video
// with a minimum quality of 50
cam.setQuality(8192,50);
// Ensure a minimum quality of 50, no matter how much bandwidth it takes
cam.setQuality(0,50);
Set the sensativity
the next thing we need to do is set the motion level needed for the onActivity trigger (which we will use when the camera moves)
syntax:
cam.setMotionLevel(sensitivity:Number, timeout:Number )
timeout is used to determine when the activity has ended, to trigger the onActivity(false) handler. it is in miliseconds
cam.setMotionLevel(30, 500);
this is a fair example, 500 is .5 seconds,
And if the user denies?
if the user denies you access from his/her camera, you have to know to trigger stuff accordingly, I suggest you use Camera.onStatus
here is an example (From livedocs)
my_cam.onStatus = function(infoObj:Object) {
switch (infoObj.code) {
case 'Camera.Muted' :
trace("Camera access is denied");
break;
case 'Camera.Unmuted' :
trace("Camera access granted");
break;
}
};
you can keep prompting the user by using System.showSettings(2) remmember, if the user clicks "remmember setting" and he pressed "no" you're done.
Actually Capturing Video, the Video object
frist of all let's declare a Video object
var myVid:Video;
now we must attach our 'cam' object to the Video to make it valid:
myVid.attachVideo(cam);
now the video and the camera are integrated. the myVid object is actually also a movieclip since it extends it, now all you have to do is give it width and height and walla, you integrated your camera ;)
now you can:
1)add a userpic to your game
2)create video chat with XMLSockets (still very hard :P)
3)create an actual action based game
Hope I helped, ask any questions