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

 

Reply via email to