mkeefe
PhotoshopCafe Developer
    
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
|
|
|
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]
|
|
|
TheDoc
Addict
   
Posts: 1635
Registered: 5/26/2007
Location: Victoria, BC
Member Is Offline
Mood: stressed... always
|
|
posted on 6/16/2008 at 04:42 PM
|
|
|
Show off 
Well done sir!
|
|
|
|