Hi,
I have two functions in the same file, how can I use the first function as default value in the second function.
public static function get decimalFormatter1():NumberFormatter{
//
}
I try this:
public static function secondFunction(param1:String, param2:Int=0, param3:Function=decimalFormatter1):Array{
//
}
Getting error: -1047: Parameter initializer unknown or is not a compile-time constant.
Any ideas?
Thanks!
decimalFormatter1 is a getter, so when you write the parameter
param3:Function = decimalFormatter
the default value is the result of calling the getter (i.e., it is the NumberFormatter returned by the getter); it isn't a Function. There is no way to treat a getter or setter as a Function object.
Gordon Smith, Adobe
As a workaround, you could use null as a default value, where null means "use decimalFormatter1". You'd write something like
public static function secondFunction(param1:String, param2:int = 0, param3:Function = null):Array
{
var formatter:Function = null;
if (param3 == null)
formatter = decimalFormatter1;
....
}
Thanks for you reply and help Gordon.
I am getting this error at the decimalFormatter1 line:
-1067: Implicit coercion of a value of type mx.formatters:NumberFormatter to an unrelated type Function.
Here is my simple get function:
public static function get decimalFormatter1():NumberFormatter{
var decimalFormatter:NumberFormatter = new NumberFormatter();
decimalFormatter.rounding = "nearest";
decimalFormatter.precision=1;
decimalFormatter.useNegativeSign = false;
return decimalFormatter;
}
Any other way?
North America
Europe, Middle East and Africa
Asia Pacific