Index: uploader.js =================================================================== --- uploader.js (revision 13936) +++ uploader.js (working copy) @@ -16,6 +16,7 @@ // set params to uploader this._eventQueue = []; this.uploadCancelled = false; + this.flashReady = false; this.params = params; this._ensureDefaultValues(); @@ -26,6 +27,8 @@ this.uploadURL = params.uploadURL; this.deleteURL = params.deleteURL; + + this.enableUploadButton(); } /* ==== Private methods ==== */ @@ -198,6 +201,21 @@ } } +Uploader.prototype.enableUploadButton = function() { + var $me = this; + + // enable upload button, when flash is fully loaded + this.queueEvent( + function() { + setTimeout( + function () { + $me.callFlash('SetButtonDisabled', [false]); + }, 0 + ) + } + ); +} + Uploader.prototype.renderBrowseButton = function() { var holder = document.getElementById(this.params.buttonPlaceholderId); this.swf.write(holder); @@ -515,6 +533,11 @@ // Queue the event this._eventQueue.push(function_body); + if (!this.flashReady) { + // don't execute any flash-related events, while it's not completely loaded + return ; + } + // Execute the next queued event setTimeout( function () { @@ -523,6 +546,21 @@ ); }; +Uploader.prototype._executeQueuedEvents = function() { + var $me = this; + + setTimeout( + function () { + $me._executeNextEvent(); + + if ($me._eventQueue.length > 0) { + $me._executeQueuedEvents(); + } + + }, 0 + ); +} + // Private: callFlash handles function calls made to the Flash element. // Calls are made with a setTimeout for some functions to work around // bugs in the ExternalInterface library. @@ -585,16 +623,8 @@ Uploader.prototype.onFlashReady = function() { var $me = this; + this.flashReady = true; - this.queueEvent( - function() { - setTimeout( - function () { - // enable upload button, when flash is fully loaded - $me.callFlash('SetButtonDisabled', [false]); - }, 0 - ) - - } - ); + // process events, queued before flash load + this._executeQueuedEvents(); } \ No newline at end of file