tags:

views:

33

answers:

2

for String and Object type, I can set the default parameter to null to indicate that it was not set by the caller. Is there a mechanism in flex3 to do the same for the Number type?

So for instance: public function myMethod( stringVar:String=null, ObjectVar:Object=null, numberVar:Number ) { ... }

I could do the following, but it just feels ugly

public function myMethod( numberVarObj:Object=null ) 
{
 var numberVarSet:Boolean=true;
if( numberVarObj == null ) {
     numberVarSet = false;
 }

 and then everywhere I want to use numberVar I can check for numberVarSet and cast as a Number.
A: 

I suppose you could always try:

var numberVar:* = null;

And then set it to a number when you want . . . It would be nice to have a solution that is strongly typed though.

Another option, as specified in Adobe's Docs (scroll down to default values), would be to treat the value NaN as null. However, if your data has ANY chance of containing a NaN value, this is a horrible idea.

Walt W
A: 

I'd recommend the "ugly" solution you have, but if you really want another option you can use NaN and then use isNaN(num) to check the value.

Richard Szalay