2 Replies Latest reply on Dec 28, 2006 12:00 PM by awclemen

    FileReferenceList doesn't return a complete event

      Hello Forum Folks!

      I have an application that uploads files. Uploading files one at time with FileReference works. No problems. But when I try to use FileReferenceList, the FileReference objects in the FileReferenceList array do not return a Event.COMPLETE when they are finished. Both versions go against the same servlet, so I am assuming that there shouldn't be any problem on the recieving end. When I throw in some debug code, I see the FileReferenceList object return open and progress events but never a complete event. Here's what my code does:

      The User clicks the 'Browse' button and selects the files. When they are finished, the 'Upload' button is enabled and they user clicks on it. I make a few calls to a database to retrieve some document identifiers and then I go through the upload process:

      var fileReference:FileReference = FileReference(this.uploadFileArray.pop());
      fileReference.addEventListener(Event.OPEN, traceEvent);
      fileReference.addEventListener(Event.COMPLETE, completeEvent);
      fileReference.addEventListener(IOErrorEvent.IO_ERROR, traceEvent);
      fileReference.addEventListener(ProgressEvent.PROGRESS, progressEvent);
      fileReference.addEventListener(SecurityErrorEvent.SECURITY_ERROR, traceEvent);
      var req:URLRequest = new URLRequest(endpoint + paramString);
      req.method = URLRequestMethod.POST;
      fileReference.upload(req, "whatever", false);
      progressBar.label = "Uploading...";
      btnCancelFile.enabled = true;

      Here's my 'complete event' handler:

      private function completeEvent(event:Event):void {
      mx.controls.Alert.show("event completed.");

      I'm pretty much following the code in the Language Reference. Is the complete event being blocked or am I completely missing something obvious?

      I'll take any suggestions or hints! Thanks in advance for the help!

        • 1. Re: FileReferenceList doesn't return a complete event
          Level 1
          OK, I still haven't been able to get the complete event to fire. Has anyone had any luck with this using the FileReferenceList? I did a "tcpdump" on my machine and I can see that the browser is recieving the HTTP 200 code from server and the server is successfully uploading the files.

          Has there been any bugs on this? Anybody got any hints?

          My only other solution is too compare the bytesloaded with the bytestotal from the progress event and shoot off the complete event myself - which is a total hack, but I'm not sure what else to do.

          • 2. Re: FileReferenceList doesn't return a complete event
            Level 1
            It appears, that unless you keep a handle on the FileReference object, the flash engine will garbage collected it real quick. Which is what was happening here - even though the files were being sent to the servlet with no problem, the garbage collector was sucking up the FileReference objects before they could dispatch the complete event.

            So, the solution here, was to place the FileReference object in an array just before the upload command and then, remove it from the array when the complete event is fired, so the garbage collection can collect it at the proper time.

            This was actually in the documentation somewhere, but for some reason it just didn't register.

            Anyhoo.... there is a good example of what to do on the lang spec in the FileReferenceList page under the examples.

            Hopes this helps... someone. :-)