24
2013
07

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;

};




版权声明:
作者:真爱无限 出处:http://www.pukuimin.top 本文为博主原创文章版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接.
« 上一篇下一篇 »

相关文章:

评论列表:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。