问题
I am trying to get SWFUpload to properly upload an image to my server, along with other post data that must come with the image. There is a form to fill up the data so after the user clicks the browse button and selects his image file, the image is not uploaded right away. It is kept in the queue until the user clicks a send button, I then call mySwfUploadInstance.startUpload() so that the upload starts.
But it fails miserably at line 452 of swfupload.js in the function 'callFlash':
Uncaught Call to ReturnUploadStart failed
The exception being caught 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's 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 being a valid flash object.
I do not get that error if I call startUpload() inside the function I pass to 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 upload to when the user completes the form and click the send button.
Any idea what is wrong with SWFUPload when I call startUpload() out of the dialog complete handler?
回答1:
It seems the problem was because I was hiding the div containing the flash object by setting display:none on it, right before calling startUpload(). I was doing this to hide the form and show a div with a progress bar instead.
For some reason the flash object must remain visible on screen else all calls made to it would fail.
来源:https://stackoverflow.com/questions/12271105/swfupload-startupload-fails-if-not-called-within-the-file-dialog-complete-hand