我了解到,在检索SWF文件并在执行此操作时将参数传递给该文件时,有两种方法可以执行此操作:使用FlashVars或查询字符串技术。

假设我希望直接通过HTTP获取swf文件,以便我可以下载该文件,并且从源代码中得知,该文件在嵌入时会通过FlashVars使用以下Javascript代码传递以下参数:

// used to validate hour parameter
            var numberOfSegments = 1;

            var flashvars1 = {};
            flashvars1.url = "http://cm.dce.harvard.edu/2014/02/23515/L12/23515-20140502-L12-H264HighBandwidthTalkingHead-16x9.xml";
            flashvars1.videoWidth = "374";
            flashvars1.videoHeight = "210";
            flashvars1.resizable = true;
flashvars1.hour = 1;
flashvars1.autoPlay = true;
flashvars1.largeTH = false;
flashvars1.cdn = false;


            //<!--
            // This will create or overwrite optional HOUR parameter
            // Tests if URL had query argument: "?part=3"
            // Checking for part in range prevents flash #1006 error
            if (location.search != ""){
                var queryStr = location.search.split('?');
                if(queryStr.length > 1){
                    queryStr = queryStr[1];
                    var queryArray = queryStr.split("&");
                    for ( var i = 0; i < queryArray.length; i++){
                        var pair = queryArray[i].split("=");
                        if ((pair[0] == "part") && (pair.length > 1) && !isNaN(pair[1])){
                            if((numberOfSegments != null) && (0 < pair[1]) && (pair[1] <= numberOfSegments) ){
                                flashvars1.hour = pair[1];
                            } // make sure hour value is in range
                        } // end if HOUR is part of query
                    }  // end query pair array loop
               }  // end if query has content
            } // end if query exists
            // -->
            var params1 = {};
            params1.quality = "high";
            params1.bgcolor = "#ffffff";
            params1.allowscriptaccess = "sameDomain";
            params1.allowfullscreen = "true";
            params1.wmode = "transparent";

            var attributes1 = {};
            attributes1.id = "flashContent1";
            attributes1.name = "flashContent1";
            attributes1.align = "middle";

            swfobject.embedSWF(
                "/flash/FlashViewer.swf", "flashContent1",
                "100%", "100%",
                swfVersionStr, xiSwfUrlStr,
                flashvars1, params1, attributes1);


然后,如何将FlashVars转换为可以在swf URL末尾附加的查询字符串?

最佳答案

这应该为您提供一个查询字符串,其中包含flashvars1 JSON对象中的所有值:

var querystring = "?";
for (var key in flashvars1) {
  if (flashvars1.hasOwnProperty(key)) {
    querystring += key + "=" + flashvars[key] + "&";
  }
}

07-26 06:54