...

View Full Version : How to have optional parameters in a function



m2244
06-29-2012, 02:34 PM
In the function below I would like to be able to pass an XML file to the SWF. I would like this to be optional, so that I can use this function with SWFs that do not have XML input. Is this possible?



function loadSwfToDiv(swf_url, div_id, ww, hh)
{
var flashvars = {};
var params = {};
params.wmode = "transparent";
var attributes = {};
swfobject.embedSWF(swf_url, div_id, ww , hh, "9.0.0", false, flashvars, params, attributes);
}

jmrker
06-29-2012, 03:18 PM
Which function argument determines whether or not the function will be executed?
When "swf_url" is blank?

m2244
06-29-2012, 04:05 PM
Which function argument determines whether or not the function will be executed?
When "swf_url" is blank?

The function is called from the html page. I would like to have the option to pass an XML file, OPTION.



<script type="text/javascript">
loadSwfToDiv("c2/data/sld10.swf", "c2",600,500)
</script> <div id="c2" />

jmrker
06-29-2012, 07:28 PM
I guess I don't know enough about 'swf' files nor XML file options to be of any help.

WolfShade
06-29-2012, 08:00 PM
function loadSwfToDiv(swf_url, div_id, ww, hh) {
var swf_url_var = !swf_url ? code if argument empty : code if argument not empty ;Is this what you are asking? Basically, if an argument is not passed, default it; if it is passed, use it?

felgall
06-30-2012, 02:53 AM
Put your optional parameters last when you define your JavaScript functions.

See http://javascriptexample.net/usefunction09.php for an example of how you then test if the optional value is supplied and set it to the default value if it isn't.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum