Skip to main content
Participating Frequently
July 28, 2014
Answered

AS3 URLLoader.load not working

  • July 28, 2014
  • 2 replies
  • 2685 views

I have a Flash app that I use to capture a webcam pic and save the image to a server database using classic ASP. I used to use NavigateToURL. Since the recent security updates (I'm testing with Flash 14.0.0.145) I've switched to URLLoader.load. It works on my local test environment, but does not work on the QA server at the client site, that is, the ASP doesn't receive the data and the photo isn't stored in the DB (I have absolutely NO ACCESS to the customer's server).

  • It is NOT cross-domain. The Flash swf is on the same server/same domain as the page I'm loading to.
  • Load fires the completeHandler, and I don't get any errors (but loader.data is blank; not sure what to look at to see number of bytes sent???)
  • In the ASP page, I tried storing Request.TotalBytes to see if I'm getting anything but it doesn't work (no database entry is made).

Ideas for things to try, solution?

Code:

function UploadImage(e:MouseEvent):void {

  var previewW:int = 94;

  var previewH:int = 118;

  var CropRectX:int = CropRect.x + 83;

  var CropRectY:int = CropRect.y + 28.5;

  //create a bitmap the size of the crop box

  var croppedBD:BitmapData = new BitmapData(CropRectCurrWidth, CropRectCurrHeight, false, 0x0000CC44);

  //create a rectangle relative to the cropbox in the video pane

  var rect:Rectangle = new Rectangle(CropRectX, CropRectY, CropRectCurrWidth, CropRectCurrHeight);

  var pt:Point = new Point(0,0);

  //copy the pixels from the crop area to the new bitmapData object

  croppedBD.copyPixels(cameraCaptureBD, rect, pt);

  var jpgEncoder:JPGEncoder = new JPGEncoder(100); // argument is the quality parameter

  var jpgStream:ByteArray = jpgEncoder.encode(croppedBD);

  //source: http://stackoverflow.com/questions/597947/how-can-i-send-a-bytearray-from-flash-and-some-form-data-to-php

  var loader:URLLoader = new URLLoader();

  configureListeners(loader);

  var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");

  var request:URLRequest = new URLRequest(SaveURL);  //value: "SavePhoto.asp"

  request.requestHeaders.push(header);

  request.method = URLRequestMethod.POST;

  request.data = jpgStream;

  try

  {

  loader.load(request);

  try

  {

  navigateToURL(new URLRequest(DoneURL), "_top");  //DoneURL = "PrintPassesFrame.asp#" & [passID Num]

  } catch (error:Error)

  {

  msg.text = msg.text + error.message;

  }

  } catch (error:Error)

  {

  msg.text = msg.text + error.message;

  }

         function configureListeners(dispatcher:IEventDispatcher):void {

            dispatcher.addEventListener(Event.COMPLETE, completeHandler);

            dispatcher.addEventListener(Event.OPEN, openHandler);

            dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);

            dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

            dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);

            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

        }

         function completeHandler(event:Event):void {

            var loader:URLLoader = URLLoader(event.target);

  msg.text = msg.text + "completeHandler: " + loader.data;

   

            var vars:URLVariables = new URLVariables(loader.data);

  msg.text = msg.text + "The answer is " + vars.answer;

        }

         function openHandler(event:Event):void {

  msg.text = msg.text + "openHandler: " + event;

        }

         function progressHandler(event:ProgressEvent):void {

            trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);

  msg.text = msg.text + "progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal;

        }

         function securityErrorHandler(event:SecurityErrorEvent):void {

  msg.text = msg.text + "securityErrorHandler: " + event;

        }

         function httpStatusHandler(event:HTTPStatusEvent):void {

  msg.text = msg.text + "httpStatusHandler: " + event;

        }

         function ioErrorHandler(event:IOErrorEvent):void {

  msg.text = msg.text + "ioErrorHandler: " + event;

        }

}

This topic has been closed for replies.
Correct answer kglad

no.


i can't help you with that.

use a network analyzer to see what's going on.

2 replies

Allegro63Author
Participating Frequently
July 28, 2014

Update:

On database insert receive #2032: Stream Error

kglad
Community Expert
Community Expert
July 28, 2014

change your allowscriptaccess to always.

Allegro63Author
Participating Frequently
July 28, 2014

I just tested setting allowscriptaccess to always (it was sameDomain) but it didn't help.

Here are the messages I'm getting:

openHandler: [Event type="open" bubbles=false cancelable=false eventPhase=2]

progressHandler loaded:391 total: 391

httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=500 redirected=false responseURL=null]

ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032"]

kglad
Community Expert
Community Expert
July 28, 2014

you have to debug on the server.  if you can't upload your test files to the server, there's no way to debug.

Allegro63Author
Participating Frequently
July 28, 2014

I am testing on the server, I meant that I can't change settings on the server, such as security policies.