天天看點

js與flash互動操作1

//flash裡傳送值

'<param name="flashvars" value="' + this.getFlashVars() + '" />'

//flash裡擷取值

this.uploadURL=root.loaderinfo.parameters.uploadURL

SWFUpload.prototype.getFlashVars = function () {

   // Build a string from the post param object

   var paramString = this.buildParamString();

   var httpSuccessString = this.settings.http_success.join(",");

   // Build the parameter string

   return ["movieName=", encodeURIComponent(this.movieName),

           "&uploadURL=", encodeURIComponent(this.settings.upload_url),

           "&useQueryString=", encodeURIComponent

(this.settings.use_query_string),

           "&requeueOnError=", encodeURIComponent

(this.settings.requeue_on_error),

           "&httpSuccess=", encodeURIComponent(httpSuccessString),

           "&assumeSuccessTimeout=", encodeURIComponent

(this.settings.assume_success_timeout),

           "&params=", encodeURIComponent(paramString),

           "&filePostName=", encodeURIComponent

(this.settings.file_post_name),

           "&fileTypes=", encodeURIComponent(this.settings.file_types),

           "&fileTypesDescription=", encodeURIComponent

(this.settings.file_types_description),

           "&fileSizeLimit=", encodeURIComponent

(this.settings.file_size_limit),

           "&fileUploadLimit=", encodeURIComponent

(this.settings.file_upload_limit),

           "&fileQueueLimit=", encodeURIComponent

(this.settings.file_queue_limit),

           "&debugEnabled=", encodeURIComponent

(this.settings.debug_enabled),

           "&buttonImageURL=", encodeURIComponent

(this.settings.button_image_url),

           "&buttonWidth=", encodeURIComponent(this.settings.button_width),

           "&buttonHeight=", encodeURIComponent

(this.settings.button_height),

           "&buttonText=", encodeURIComponent(this.settings.button_text),

           "&buttonTextTopPadding=", encodeURIComponent

(this.settings.button_text_top_padding),

           "&buttonTextLeftPadding=", encodeURIComponent

(this.settings.button_text_left_padding),

           "&buttonTextStyle=", encodeURIComponent

(this.settings.button_text_style),

           "&buttonAction=", encodeURIComponent

(this.settings.button_action),

           "&buttonDisabled=", encodeURIComponent

(this.settings.button_disabled),

           "&buttonCursor=", encodeURIComponent

(this.settings.button_cursor)

       ].join("");

};

//js調用flash中的方法

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;

//調用

SWFUpload.prototype.getStats = function () {

   return this.callFlash("GetStats");

SWFUpload.prototype.getFile = function (fileID) {

   if (typeof(fileID) === "number") {

       return this.callFlash("GetFileByIndex", [fileID]);

   } else {

       return this.callFlash("GetFile", [fileID]);

SWFUpload.prototype.addFileParam = function (fileID, name, value) {

   return this.callFlash("AddFileParam", [fileID, name, value]);

SWFUpload.prototype.getMovieElement = function () {

   if (this.movieElement == undefined) {//this.movieName就是flash object的id

       this.movieElement = document.getElementById(this.movieName);

   if (this.movieElement === null) {

       throw "Could not find Flash element";

   return this.movieElement;

繼續閱讀