I have a function that I would like to pass in null for the parameters so that the default param values get picked up but it doesn’t seem to like null, undefined or NaN.
Here is my function:
function myFunction(value:Number = .5, value2:Number = .6):Number {
return value;
}
and then later:
var result = myFunction(null, 10);
trace(result); // 0
var result = myFunction(NaN, 10);
trace(result); // NaN
var result = myFunction(undefined, 10);
trace(result); // NaN
How do I get it to default to .5?
If you call your function without passing parameters, you should get the default value as you expect. In your example, the default value is only used if a value is not passed at all.
If you are wanting to pass a second parameter but not the first, then you might have to consider an alternative approach.
Vars typed to ‘Number’ in AS3 cannot have the value null and will be converted to NaN automatically.