RE: [flexcoders] Re: Calling functions with optional parameters
This produces the compilation warning 1102: null used where a int value was expected. I'm surprised that it doesn't produce a compilation error, and I'll ask the AS3 folks about that. Gordon Smith Adobe Flex SDK Team From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Tracy Spratt Sent: Friday, November 14, 2008 5:38 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Re: Calling functions with optional parameters If you pass a null value to an optional parameter, the function uses the default values defined in the declaration. ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=absolute mx:Script![CDATA[ import mx.controls.Alert; import mx.core.Application; public var app:* = null; /** */ private function doTest():void { funcTest(null,null,bar); }// private function funcTest(param1:int=0, param2:int=1,param3:String='foo'):void { Alert.show(param1= + param1 + param2= + param2 + param3= + param3) }//funcTest ]]/mx:Script mx:Button label=test click=doTest() / /mx:Application Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Amy Sent: Friday, November 14, 2008 5:02 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Calling functions with optional parameters --- In flexcoders@yahoogroups.commailto:flexcoders%40yahoogroups.com, Tracy Spratt [EMAIL PROTECTED] wrote: What if you explicitly passed null? theFunction(null,null,'bar'); The defaults aren't always null, and MPO is that the developer shouldn't need to know what the appropriate default is to make the default behavior. I feel like I'm really sure that I've seen places in the framework code where functions are called this way, but I'm not sure how to search in there to get verification. It would be really, really nice if the docs were detailed enough that I could get a good sense of whether I'm barking up the wrong tree (of course the docs are wrong or misleading a good percentage of the time, so detail is no guarantee) ;-). Thanks; Amy
RE: [flexcoders] Re: Calling functions with optional parameters
If you pass a null value to an optional parameter, the function uses the default values defined in the declaration. I don't think so. The output I get is param1=0 param2=0 param3=bar If it was using the default values, param2 would be 1, not 0. I think it is simply coercing null to 0. Gordon Smith Adobe Flex SDK Team From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Gordon Smith Sent: Tuesday, November 18, 2008 1:15 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Re: Calling functions with optional parameters This produces the compilation warning 1102: null used where a int value was expected. I'm surprised that it doesn't produce a compilation error, and I'll ask the AS3 folks about that. Gordon Smith Adobe Flex SDK Team From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Tracy Spratt Sent: Friday, November 14, 2008 5:38 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Re: Calling functions with optional parameters If you pass a null value to an optional parameter, the function uses the default values defined in the declaration. ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=absolute mx:Script![CDATA[ import mx.controls.Alert; import mx.core.Application; public var app:* = null; /** */ private function doTest():void { funcTest(null,null,bar); }// private function funcTest(param1:int=0, param2:int=1,param3:String='foo'):void { Alert.show(param1= + param1 + param2= + param2 + param3= + param3) }//funcTest ]]/mx:Script mx:Button label=test click=doTest() / /mx:Application Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Amy Sent: Friday, November 14, 2008 5:02 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Calling functions with optional parameters --- In flexcoders@yahoogroups.commailto:flexcoders%40yahoogroups.com, Tracy Spratt [EMAIL PROTECTED] wrote: What if you explicitly passed null? theFunction(null,null,'bar'); The defaults aren't always null, and MPO is that the developer shouldn't need to know what the appropriate default is to make the default behavior. I feel like I'm really sure that I've seen places in the framework code where functions are called this way, but I'm not sure how to search in there to get verification. It would be really, really nice if the docs were detailed enough that I could get a good sense of whether I'm barking up the wrong tree (of course the docs are wrong or misleading a good percentage of the time, so detail is no guarantee) ;-). Thanks; Amy
RE: [flexcoders] Re: Calling functions with optional parameters
Huh, my turn for the Doh! Funny how often we see what we expect, rather than what is there. So, Amy, we have not solved your problem, and hopefully not caused you much inconvenience. I could have sworn I did this somehow. Maybe undefined? I'll have to try that. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Gordon Smith Sent: Tuesday, November 18, 2008 4:25 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Re: Calling functions with optional parameters If you pass a null value to an optional parameter, the function uses the default values defined in the declaration. I don't think so. The output I get is param1=0 param2=0 param3=bar If it was using the default values, param2 would be 1, not 0. I think it is simply coercing null to 0. Gordon Smith Adobe Flex SDK Team From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Gordon Smith Sent: Tuesday, November 18, 2008 1:15 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Re: Calling functions with optional parameters This produces the compilation warning 1102: null used where a int value was expected. I'm surprised that it doesn't produce a compilation error, and I'll ask the AS3 folks about that. Gordon Smith Adobe Flex SDK Team From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Tracy Spratt Sent: Friday, November 14, 2008 5:38 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Re: Calling functions with optional parameters If you pass a null value to an optional parameter, the function uses the default values defined in the declaration. ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml http://www.adobe.com/2006/mxml layout=absolute mx:Script![CDATA[ import mx.controls.Alert; import mx.core.Application; public var app:* = null; /** */ private function doTest():void { funcTest(null,null,bar); }// private function funcTest(param1:int=0, param2:int=1,param3:String='foo'):void { Alert.show(param1= + param1 + param2= + param2 + param3= + param3) }//funcTest ]]/mx:Script mx:Button label=test click=doTest() / /mx:Application Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Amy Sent: Friday, November 14, 2008 5:02 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Calling functions with optional parameters --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Tracy Spratt [EMAIL PROTECTED] wrote: What if you explicitly passed null? theFunction(null,null,'bar'); The defaults aren't always null, and MPO is that the developer shouldn't need to know what the appropriate default is to make the default behavior. I feel like I'm really sure that I've seen places in the framework code where functions are called this way, but I'm not sure how to search in there to get verification. It would be really, really nice if the docs were detailed enough that I could get a good sense of whether I'm barking up the wrong tree (of course the docs are wrong or misleading a good percentage of the time, so detail is no guarantee) ;-). Thanks; Amy
RE: [flexcoders] Re: Calling functions with optional parameters
Actually I find formatting code on this list generally to be a pain. That particular formatting is some magic that happens when I copy code from the Flex Bulder 3 code editor in to Outlook, where I use MSWord as the editor. It did not happen with FB2. And the html format introduces extra CRs. The cognitive states of software development: Huh? Hmm. Aha! Duh! Doh! Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Amy Sent: Friday, November 14, 2008 10:10 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Calling functions with optional parameters --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Tracy Spratt [EMAIL PROTECTED] wrote: If you pass a null value to an optional parameter, the function uses the default values defined in the declaration. Great, Tracy. Way to make me feel like a dope ;-). BTW, how do you get such pretty formatting?
RE: [flexcoders] Re: Calling functions with optional parameters
You can write either MyClass.foo = bar; or MyClass[foo] = bar; to set a static property of a class. Gordon Smtih Adobe Flex SDK Team From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Amy Sent: Friday, November 14, 2008 2:28 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Calling functions with optional parameters --- In flexcoders@yahoogroups.commailto:flexcoders%40yahoogroups.com, Maciek Sakrejda [EMAIL PROTECTED] wrote: Amy, Fotis is right--if you want to specify a param that has a default, you need to specify all parameters to the left of it in the argument list. Depending on your function and how many parameters it has, you may want to add a class to represent your function arguments, construct that object independently, and pass that to your function. E.g., var args:FunctionArgs = new FunctionArgs(); args.foo = 123; args.bar = baz; theFunction(args); This doesn't always make sense, but it can help. OK, this sort of makes sense...but... I don't want to create a special class for every place I want to do this. So I thought I know, I'll just use a generic object and check to see what properties it has. So I am using something like: for (s:string in paramObj) { this[s]=paramObj[s]; } Just one problem...it's a static method. Anyone know the equivalent syntax to this['thing'] that will work in a static method? Thanks; Amy
RE: [flexcoders] Re: Calling functions with optional parameters
Optional parameters must come after required parameters. Gordon Smith Adobe Flex SDK Team From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Amy Sent: Friday, November 14, 2008 2:02 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Calling functions with optional parameters --- In flexcoders@yahoogroups.commailto:flexcoders%40yahoogroups.com, Tracy Spratt [EMAIL PROTECTED] wrote: What if you explicitly passed null? theFunction(null,null,'bar'); The defaults aren't always null, and MPO is that the developer shouldn't need to know what the appropriate default is to make the default behavior. I feel like I'm really sure that I've seen places in the framework code where functions are called this way, but I'm not sure how to search in there to get verification. It would be really, really nice if the docs were detailed enough that I could get a good sense of whether I'm barking up the wrong tree (of course the docs are wrong or misleading a good percentage of the time, so detail is no guarantee) ;-). Thanks; Amy
RE: [flexcoders] Re: Calling functions with optional parameters
If you pass a null value to an optional parameter, the function uses the default values defined in the declaration. ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=absolute mx:Script![CDATA[ import mx.controls.Alert; import mx.core.Application; public var app:* = null; /** */ private function doTest():void { funcTest(null,null,bar); }// private function funcTest(param1:int=0, param2:int=1,param3:String='foo'):void { Alert.show(param1= + param1 + param2= + param2 + param3= + param3) }//funcTest ]]/mx:Script mx:Button label=test click=doTest() / /mx:Application Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Amy Sent: Friday, November 14, 2008 5:02 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Calling functions with optional parameters --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Tracy Spratt [EMAIL PROTECTED] wrote: What if you explicitly passed null? theFunction(null,null,'bar'); The defaults aren't always null, and MPO is that the developer shouldn't need to know what the appropriate default is to make the default behavior. I feel like I'm really sure that I've seen places in the framework code where functions are called this way, but I'm not sure how to search in there to get verification. It would be really, really nice if the docs were detailed enough that I could get a good sense of whether I'm barking up the wrong tree (of course the docs are wrong or misleading a good percentage of the time, so detail is no guarantee) ;-). Thanks; Amy