Skip to content

Video From Webcam in Actionscript

November 17, 2009

I’m working my way up to more advanced applications of the Video and Camera Classes in Actionscript 3.0 so I will be posting up the code each step of the way. The code below shown below is the most basic level of using a camera in Flash. The Camera used needs to be retrieved and attached to video. Additional parameters may be entered here, but if they are not specified, the default settings will be used.

</pre>
package basicCamCode{
import flash.display.MovieClip;
import flash.media.Camera;
import flash.media.Video;

public class BasicCamera extends MovieClip {

private var cam:Camera;
private var vid:Video;

public function BasicCamera() {
cam=Camera.getCamera(); //
vid=new Video(); //default dimensions are 320 x 240
vid.scaleX=-1;
vid.x=(stage.stageWidth/2)+(vid.width/2); //the scaling causes registation point to  switch to top right corner
vid.y=(stage.stageHeight/2)-(vid.height/2);
vid.attachCamera(cam);
addChild(vid);

//trace("cam width = "+cam.width); //if you don't know what dimensions your camera returns
//trace("cam height = "+cam.height);

}//ExpCamera

}//class
}//package

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: