First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
Search tutorials
Author: 123Webwizard | Website: http://webwizardinc.com

This is gonna be a short writing on the Video Capabilities of Flash Player 7! The two Classes (Actionscript 2.0) that make it possible in this verison are:

1. Camera Class
2. Video Class

The Camera class is primarily for use with Macromedia Flash Communication Server, but can be used in a limited fashion without the server and that is exactly what we are gonna do! Make a limited verison Flash Movie that can capture the video of a User who has a Web Cam attached to their PC. For example, to monitor a video feed from a web camera attached to your local system.

Here is a how the story goes!

We will do it "The Flash MX 2004 Way!". The package available with this tutorial contains three files:

Project File: wwinc_cam.flp
The .FLA Source File: mycam.fla
The .AS Actionscript Class File: MyVideoPlayer.as
The .SWF File: mycam.swf
the .HTML File: mycam.html

Project File:
*************
If you are a programmer and you've had a chance to work in Microsoft Visual Studios or JBuilder, you might have an idea of what this project file is. For non-programmers, well, its a schema file for a project. For example: Consider the file wwinc_cam.flp, it contains about the rest of the files in the our project, i.e. mycam.fla(src), mycam.swf (browser executable), so on and so forth.

The .AS Actionscript Class File:
********************************
Actionscript 2.0 defines a custom class, which lets you instantiate objects that share methods and properties that you define in a seperate .AS (actionscript file) or in the Actions Panel. But keywords such as static are on available in external Actionscript files.

For example, if you are developing an invoice-tracking system, you could create an invoice class that defines all the methods and properties that each invoice should have. You would then use the new invoice() command to create invoice objects i.e.:

var MyInvoice = new invoice();

The name of the class must be the same as the name of the external file that contains the class. For example, if you name a class MyVideoPlayer, the file that defines the class must be named MyVideoPlayer.as.

Going into the depth of class definitions is beyond the scope of this tutorial.

The MyVideoPlayer.as is our custom class file for this example. (This will also give you a hint of the Actionscript 2.0 custom class definitions). The code is well commented, so just read through it:

/******************************
Author: 123Webwizard
URL:    http://webwizardinc.com/
*******************************/

class MyVideoPlayer extends Object	{
	
	private var CamObj ;
	
	function MyVideoPlayer()	{	}

	/*Checks to see if the camera is installed or inuse!
	***************************************************/
	public function hasCamera():Boolean{
		if (null != Camera.get()) {
			return true;
		} 
		else {
			return false;
		}
	}
	/*our interface to the status field
	***********************************/
	public function setStatus(str):Void	{
		_root.status.text += str;
	}
	/*this function actually captures the video stream
	**************************************************/
	public function captureVideo(vo):Void {
		var wwinc_Cam = Camera.get();
		/*Changing the default fps*/
		wwinc_Cam.setMode(280, 210, 30);
		/*Ensuring 4096 bytes/sec (4K/second) to send
		video with a minimum quality of 50 */
		wwinc_Cam.setQuality(4096, 50);
		vo.attachVideo(wwinc_Cam);
		/*Video should be smoothed (interpolated) as we have scaled
		the video object on the stage*/
		vo.smoothing = true;		
		/*Exporting the Camera Object for further use*/
		setCameraObject(wwinc_Cam);
	}

	private function setCameraObject(co){
		this.CamObj = co;
	}

	public function getCamera():Camera{
		return this.CamObj;
	}
}

The .FLA Source File:
*********************
This is the Flash source file. It contains, the video object and a few calls to our own Actionscript Class (which would be next in this tutorial) i.e.:

/******************************
Author: 123Webwizard
URL:    http://webwizardinc.com/
*******************************/

var wwinc_mvp = new MyVideoPlayer();
with(wwinc_mvp){
	if(hasCamera()==true){
		setStatus("Capturing Devices(s) found...\n");
		captureVideo(myVideo_mc);
	}
	else{
		setStatus("No display devices are installed or in use!\n");
	}
}
/*Gets the status from Camera Object
************************************/
wwinc_mvp.getCamera().onStatus = function(msg) {	
	if (msg.code == "Camera.Muted") {
		wwinc_mvp.setStatus("User has denied access to the camera!");
	}
	else{
		with(wwinc_mvp){
			setStatus("Video Device started...\n");
			setStatus("Frames per second: " + getCamera().fps + "\n");
		}
	}
};
wwinc_mvp.getCameraObject().onActivity = function(activity) {
	/*
	Event handler; invoked when the camera starts or stops 
	detecting motion. If you want to respond to this 
	event handler, you must punch in your statements here!! 
	*/	
};

Other files:
************
These two files are self explainatory! ;-)
The .SWF File:                    mycam.swf
the .HTML File:                   mycam.html

Hope it was of any use to people... I tried to give the background and all within a small time range!

Have a ball!
123Webwizard.(Nasir Ali Sher)
http://webwizardinc.com/

» Level Advanced

Added: 2003-09-25
Rating: 7 Votes: 29
(10 being the highest)
» Author
I'm a Software Engineer and I do Flash MX is my spare time... I just love the tool!
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: doc_chin7
» Description:

The flash's horizontal road drive was done in CS4 and was upgraded to CS6. The car responds to right/ left key and flash will auto-generate the movement of roads from left-right or right-left based on random number. Have fun driving in this virtual environment and avoid other cars... :) If you are creative, a road driving game can be created from it.

Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.