SWFUpload startUpload () fails if not called in file_dialog_complete_handler

I am trying to get SWFUpload to upload the image to my server correctly along with other messages that should appear along with the image. There is a form for filling data, so after the user clicks the browse button and selects his image file, the image does not load immediately. It is kept in the queue until the user clicks the submit button, then I will call mySwfUploadInstance.startUpload () to start the download.

But it does not cope with the error in line 452 swfupload.js in the function 'callFlash':

Uncaught Call to ReturnUploadStart failed

The exception before throwing this error is the following:

Object #<HTMLObjectElement> has no method 'CallFunction'

in the following function:

 SWFUpload.prototype.callFlash = function (functionName, argumentArray) { argumentArray = argumentArray || []; var movieElement = this.getMovieElement(); var returnValue, returnString; // Flash method if calling ExternalInterface methods (code adapted from MooTools). try { returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>'); returnValue = eval(returnString); } catch (ex) { throw "Call to " + functionName + " failed"; } // Unescape file post param values if (returnValue != undefined && typeof returnValue.post === "object") { returnValue = this.unescapeFilePostParams(returnValue); } return returnValue; }; 

movieElement looks like a valid flash object.

I do not get this error if I call startUpload () inside the function that I pass file_dialog_complete_handler when initializing SWFUpload:

 function ImageFileDialogComplete(numFilesSelected, numFilesQueued) { try { this.startUpload(); } catch (ex) { this.debug(ex); } } 

I really need to be able to postpone the download before the user fills out the form and click submit.

Any idea what is wrong with SWFUPload when I call startUpload () from the full dialog handler?

+6
source share
1 answer

It seems that the problem was that I was hiding the div containing the flash object by setting the display to: none on it, right before the startUpload () call. I did this to hide the form and show a div with a progress bar.

For some reason, the Flash object must remain visible on the screen, otherwise all calls made with it will fail.

+14
source

Source: https://habr.com/ru/post/924592/


All Articles