Reputation: 904
I understand that when retrieving an SWF file and passing parameters to that file while doing so, there are two options to do this: using the FlashVars or the query string technique.
Say I wish to obtain the swf file directly via HTTP so that I can download the file, and I know from the source code that the file, when embedded, is passed the the following parameters via FlashVars with the following Javascript code:
// 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);
How then do I translate FlashVars into a query string I can append at the end of the swf URL?
Upvotes: 0
Views: 773
Reputation: 134
This should give you the a query string with all the values from the flashvars1 JSON object:
var querystring = "?";
for (var key in flashvars1) {
if (flashvars1.hasOwnProperty(key)) {
querystring += key + "=" + flashvars[key] + "&";
}
}
Upvotes: 1