Official website for Web Designer - defining the internet through beautiful design
FOLLOW US ON:
Subs House Ad
Apr
27

Add webcam fun with Flash

by Dave Harfield

16 Video test

152-052-step016

Remember you added the video to the library at the beginning of the tutorial? Well, now we need to add an instance of the video to the stage by dragging the clip from the library. Open this in the Property Inspector, and call the video object ‘videoTest’ in the instance name field.

17 Code layer

Create a new layer called ‘code’, then open the Actions panel (Ctrl+F9). Before you can use the webcam, you need to do a couple of import statements. Import the Camera and Video class from the flash.media package. These will be used to connect to your webcam and then display the output via the video class.

import flash.media.Camera;
import flash.media.Video;

18 New camera object
Next, you need to create a new camera object using the camera class with the getCamera method. This will start up the web camera input. Now you have the camera, it’s good practice to check if the camera is working before you assign the video. Do this using an if statement.

var camera:Camera = Camera.getCamera();
if (camera != null) {

19 Need a camera?
Next, attach the newly created video object to the camera object just coded. A measure of good practice is to add an else statement inside the if statement, which will trace out to say you need a webcam if your camera is equal to null. Last of all, place a stop().

videoTest.attachCamera(camera);
} else {
trace(“You need a camera.”);
}
stop();

20 Lion video

152-052-step020

Test your movie and you should see yourself in the little screen. Using this as a guide, add another layer called ‘LionVideo’. Add a video to the stage and call it ‘videoLion’, positioning it so your head in the test camera is where the lion’s head is. You might have to scale the video object so your head is not too large for the image.

Pages: 1 2 3 4 5

3 Comments »

  • photo retouching said:

    A nice way to spice up webcams! nice tut

  • webcam fun with Flash | Designer Depot said:

    [...] webcam fun with Flash May 13, 2009 | In ActionScript 3.0, Adobe Flash | [...]

  • Ganry74 said:

    It drives not only the Boom but also a monocular projector that displays on a 4-foot by 6-foot screen at one end of a nearby conference table that seats eight. ,

What's your opinion?

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.