Webcam snapshot

I have followed Lee’s tutorials on saving snapshot from webcam, but now I found out that I need it to be in a normal swf file rather than an air application. How could I change the code here?


import com.adobe.images.PNGEncoder;
import flash.filesystem.*;

var cam:Camera = Camera.getCamera();
var video:Video = new Video(240,180);

cam.setQuality(0, 100);

video.attachCamera(cam);
//video.x = -52.5;
frame.addChild(video);

btn.addEventListener(MouseEvent.CLICK,saveImage);

var count:int = 0;
//how to start from last number;

var scale:Number = .45;

var m:Matrix = new Matrix();
m.scale(scale,scale);

function saveImage(e:MouseEvent):void {
    var bmd:BitmapData = new BitmapData(60,80,false);
    bmd.draw(video,m);
    var ba:ByteArray = PNGEncoder.encode(bmd);
    var file:File = File.desktopDirectory.resolvePath("card" + count++ +".png" );
    var fileStream:FileStream = new FileStream();
    fileStream.open(file,FileMode.WRITE);
    fileStream.writeBytes(ba);
    fileStream.close();
}

I wanted to save the snapshot to a folder where my swf is.
Currently the code save the picture from 0 every time i open the swf. How can I save the filename after the last image in that folder?

You won’t be able to save an image out of flash to the filesystem if it’s not an AIR application.

Can the air run on9? And like save it to server?

You can send a byte array to a server, yes. You will need to use as3corelib to convert your bitmapdata into a jpeg. I use AMFPHP on my site [URL=“http://www.cellpaint.com”]cellpaint.com to ‘catch’ the bytearray and write it to the server.