Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-29-2012, 02:34 PM   PM User | #1
m2244
Regular Coder

 
Join Date: Jun 2012
Posts: 127
Thanks: 1
Thanked 1 Time in 1 Post
m2244 is an unknown quantity at this point
How to have optional parameters in a function

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?

Code:
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);
}
m2244 is offline   Reply With Quote
Old 06-29-2012, 03:18 PM   PM User | #2
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,763
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
Which function argument determines whether or not the function will be executed?
When "swf_url" is blank?
jmrker is offline   Reply With Quote
Old 06-29-2012, 04:05 PM   PM User | #3
m2244
Regular Coder

 
Join Date: Jun 2012
Posts: 127
Thanks: 1
Thanked 1 Time in 1 Post
m2244 is an unknown quantity at this point
Quote:
Originally Posted by jmrker View Post
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.

Code:
<script type="text/javascript"> 
loadSwfToDiv("c2/data/sld10.swf", "c2",600,500)
</script> <div id="c2" />
m2244 is offline   Reply With Quote
Old 06-29-2012, 07:28 PM   PM User | #4
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,763
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
I guess I don't know enough about 'swf' files nor XML file options to be of any help.
jmrker is offline   Reply With Quote
Old 06-29-2012, 08:00 PM   PM User | #5
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 941
Thanks: 7
Thanked 95 Times in 95 Posts
WolfShade is an unknown quantity at this point
Code:
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?
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 06-30-2012, 02:53 AM   PM User | #6
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:55 AM.


Advertisement
Log in to turn off these ads.