The Camera Object


The Camera Object

The 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() Method

The 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 Property

The 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:

1.

Create a new Flash document.

2.

Create a blank video object as you did before.

3.

Drag the blank video object onto the stage and give it an instance name of myVideo_video.

4.

Create a dynamic text field under the blank video object.

5.

Give the text field an instance name of activity_txt and make sure the border property is turned on.

6.

Create a new layer called actions.

7.

In the first frame of the Actions layer, open the Actions panel and place this code in:

 //get the web cam var myCam_cam:Camera = Camera.get(); //create the function to monitor the activity this.onEnterFrame = function(){     activity_txt.text = myCam_cam.activityLevel; } //create a blank event handler to kick-start the activityLevel property myCam_cam.onActivity=function(){}; //attach the cam to the video object myVideo_video.attachVideo(myCam_cam); 

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.





Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net