Foundation Flash 8 Video
by Tom Green and Jordan Chilcott
Excerpted from “Foundation Flash 8 Video” by Tom Green and Jordan Chilcott
© 2006. Used with the permission of
friends of ED, a division of Apress.
To purchase this book, please visit
www.friendsofed.com.
by Tom Green and Jordan Chilcott
The first thing to understand about using the camera object in Flash® is that its primary purpose is to broadcast a video feed from your camera through the Flash Media Server 2 to a SWF file in a web page. This means that if you have a Flash Media Server account with your Internet Service Provider (ISP) you can wave at Aunt Millie in Manchester, England, from your computer and, if she has a webcam, you can see her wave back at you. Though that is the primary purpose, you can also allow users with webcams who only use HTTP to stream video to see themselves and even put themselves into some rather interesting circumstances you devise.
The other aspect of using a webcam with the Flash Player is that any SWF that tries to access a camera will kick out a Privacy Settings dialog box that lets the user choose whether to allow or deny access to the camera. This dialog box also lets you choose the camera to be used. More about that in a minute. Finally, though you can connect a number of cameras to your computer, the camera object will only let you display them one at a time.
Connect your webcam to your computer and let’s start looking at different ways of using a webcam.
var myCamera:Camera = Camera.get(); myVid.attachVideo (myCamera);
The first line retrieves the camera object using the Camera.get() method and gives the camera a name by assigning it to myCamera. (You can find out more about the Camera class by using Flash help.) The second line simply attaches the feed from the camera to the video object on the stage as shown in Figure 1. That is all you need to get in the game. Go ahead; test the movie.
Tip: Though you are using a video object that is 320 by 240 to play the video feed, you can use any size you wish. Just be aware that every time the camera is detected, the Privacy Settings dialog box will appear over the SWF. This means that if you have a video object on a stage that is 160 by 120, your user is going to have a real problem because the Privacy Settings dialog box will be larger than the stage. If you do use a webcam, the minimum stage size is 215 x 138 pixels, which is the minimum size required by Flash to display the dialog box.
Figure 1: Hello World.
You may have noticed the empty parameter in the Camera.get() method. That directs Flash to use the first camera it finds that is connected to your computer. If you had three cameras, they would have index values of 1, 2, and 3. If you wanted to use the second camera the method would be Camera.get(2);
If you haven’t been able to get your camera to connect to the video object, all is not lost. Sometimes multiple camera drivers are installed and Flash may have picked the wrong one. To choose the proper driver, test the movie again and follow these steps:
Figure 2: Choose your camera through the SWF Settings dialog box.
Now you will create a video box.
var myCam: Camera = Camera.get(); myVid.attachVideo (myCam);
Figure 3: Use the Transform panel to scale and skew by the numbers.
Figure 4: The first box in position.
Note: If you really want to have some fun with this, put a bunch of the movie clip boxes on the stage and, using the startDrag () and stopDrag () methods, let the user stack the boxes.
Figure 5: Boxed in.
As you discovered in the previous section, you don’t always need to have the video on a flat plane. In this section you keep the video on that plane but the end result is a sort of kaleidoscopic effect. This is accomplished by simply “flipping” the movie clips containing the video object.
To complete this portion of the tutorial, download the zipped file Flip.fla:
Figure 6: A horizontal flip.
Figure 7: Why should carnival fun houses have all the fun?