The CAFE
Design Challenge 10

Last active: Never
Not logged in [Login - Register]
Go To Bottom

Printable Version
Subscribe | Add to Favourites

Post new thread
Author: Subject: Basic Webcam Interaction using ActionScript 3
mkeefe
PhotoshopCafe Developer
******


Avatar


Posts: 7483
Registered: 2/10/2003
Location: Boston MA, USA
Member Is Offline

Mood: Eager to code, hello Flex!

posted on 6/16/2008 at 10:17 AM Reply With Quote
Basic Webcam Interaction using ActionScript 3



After a discussion about webcams in Flash I decided to throw together a quick example.

This application creates a webcam video on the stage and then every 10 seconds takes a snapshot (in memory) where you can easily display that or save it.

Code:

// package imports
import flash.media.Camera;
import flash.media.Video;
import com.scriptplayground.image.*;
import com.scriptplayground.utils.*;

var capture:Boolean = false;
var timerDelay:uint = 10000;
var timerCount:uint = 0;
var timer:Timer;
var video:Video;
var videoContainer:MovieClip;

// master function, kick it all off
function init():void
{
var cam:Camera = Camera.getCamera();
cam.setMode(640, 480, 30);
cam.setQuality(0, 100);

video = new Video(cam.width, cam.height);
video.attachCamera(cam);

var videoContainer:MovieClip = new MovieClip();
videoContainer.addChild(video);

var vidContainer:MovieClip = new MovieClip();
vidContainer.addChild(videoContainer);

addChild(vidContainer);

timer = new Timer(timerDelay, timerCount);
timer.addEventListener(TimerEvent.TIMER, takePicture);
timer.start();

capture = true;
}

// every time this is called a jpg is created
function takePicture(e:Event=null):void
{
if(!capture) return;

// generate JPEG (would be used to save)
var byteStream:ByteArray = CreateImage.createJPEG(videoContainer, 100);
}

init();


For those keeping track, the code is 48 lines. ;)

In order to use the code you must download my class library (for this app) and you also need the AS3CoreLib from Adobe which I have included.

[Edited on 6/16/2008 by mkeefe]




Dev: PHP, AS3, Flex and AIR
Work / Photography / twitter / Scriptplayground

http://mkeefe.com/s.jpg
View User's Profile E-Mail User Visit User's Homepage View All Posts By User U2U Member mkeefe's Aim
TheDoc
Addict
*****


Avatar


Posts: 1635
Registered: 5/26/2007
Location: Victoria, BC
Member Is Offline

Mood: stressed... always

posted on 6/16/2008 at 04:42 PM Reply With Quote


Show off :lol

Well done sir!




http://storage.seethroughhead.net/talking-creative-sig.png
View User's Profile Visit User's Homepage View All Posts By User U2U Member
Post new thread


Go To Top


Version ( removed for security concerns )

[queries: 17]
[PHP: 53.2% - SQL: 46.8%]


PhotoshopCD