View Full Version : Flash and Ajax

08-12-2009, 01:17 AM
Hi I need to be able to send a bytearray object to a javascript function or a java method, but I was wondering if I could do it using XMLHTTPRequest.

import asfiles.encoding.JPEGEncoder;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.external.*;
import flash.events.Event;

var cam:Camera = Camera.getCamera();
var video:Video = new Video(280,280);
video.x = 10;
video.y = 10;

capture_mc.buttonMode = true;

function captureImage(e:MouseEvent):void {
var bitmapData:BitmapData = new BitmapData(video.width,video.height);
var myEncoder:JPEGEncoder = new JPEGEncoder(80);
var ba:ByteArray = myEncoder.encode(bitmapData);
ExternalInterface.call("captureImage", ba);

So I have a video that plays stream from a webcam, I will click a button and take a picture. I encode that picture using JPEGEncoder then I store it in a ByteArray. How do I send that data over to either a javascript function or a java class? I don't want to use the navigateToURL(URLRequest) method because that will redirect my page. Is there a way to send the data to a function while still staying on the same page? For example, make a asynchronous call to a javascript function or java method?