简体   繁体   中英

Javascript with Flash (AS3) Image Uploader, ExternalInterface.call

A flash project I'm currently working on requires me to take a series of screenshots of the stage and upload those screenshots to a server. I've written the AS3 code pasted below to send the screenshots (converted to jpegs) to a php processing script (imageprocess.php).

for (var i:int=0; i<sourceArray.length; i++)
    {
    var jpgEncoder:JPGEncoder = new JPGEncoder(10);
    var jpgStream:ByteArray = jpgEncoder.encode(sourceArray[i]);
    var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");     
    var jpgURLRequest:URLRequest = new URLRequest("imageprocess.php?name=drawing" + i +".jpg");
    jpgURLRequest.requestHeaders.push(header);
    jpgURLRequest.method = URLRequestMethod.POST;
    jpgURLRequest.data = jpgStream;
    navigateToURL(jpgURLRequest, "_blank"); //switch to ExternalInterface.call("someJS") 
    }

Unfortunately, I've discovered that navigateToURL can only function once per frame (http://www.actionscript.org/forums/showthread.php3?t=250594). It looks like I'll have to use ExternalInterface.call plus some Javascript to upload multiple screenshots, but I'm not sure what this Javascript code would look like. Would anyone be kind enough to provide some example JS which could take each of the screenshots I convert and send them to a php file? I'd really appreciate any and all advice.

You don't have to use a JavaScript and so to upload the images, why don't you just create a JavaScript function to open a new link in the browser (like a popup)? A copy of the navigateToURL function but then in JavaScript? It would be a quicker fix I suppose? Opening windows with JavaScript, read this link.

URLLoader might solve your problem. Haven't use navigatetourl for uploading, really interesting. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM