The Camera ObjectThe Camera object, which is available in the Flash 6 Player and later (but is undocumented in the 6 Player), is a way to work with web cams running on local machines. It isn't really streaming, but it is a lot of fun to work with, and it can be placed in the Video object, so I put it in this chapter. The Camera object has a lot of methods, properties, and events, but the two we are going to focus on are the get() method and the activityLevel property. The get() MethodThe get() method for the Camera object is used to get the web cam. If more than one web cam is attached to your computer, you can choose which one you want to work with; otherwise, the get() method will use the default camera. The generic layout for the get() method is as follows: myCamera_cam.get(index); The parameter index is used in case there is more than one camera attached to the computer. It is a numerical value representing each camera, starting at zero. The activityLevel PropertyThe activityLevel property returns the amount of visual activity the camera is detecting, ranging from zero to 100. This property will work only when you have created an onActivity event callback. Now let's see the Camera object at work:
The preceding code creates a reference to the web cam we are getting. Then it creates a constantly repeating event that will send the activityLevel of the web cam to the text field. After that, we create a blank event callback for the onActivity event to initialize the activityLevel property. Finally, we attach the video from the web cam to the Video object. Test the movie, and you will see something like Figure 26.9. If you get a pop-up asking to allow local access to your web cam or microphone, go ahead and allow it so that it will work. Figure 26.9. Use a web cam as another means of sending video to the Video object. |