4 Replies Latest reply: Apr 13, 2012 4:03 AM by jfb00 RSS

    Static function parameter help

    jfb00 Community Member

      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!

        • 1. Re: Static function parameter help
          GordonSmith Adobe Employee

          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

          • 2. Re: Static function parameter help
            GordonSmith Adobe Employee

            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;

             

                ....

            }

            • 3. Re: Static function parameter help
              jfb00 Community Member

              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?

              • 4. Re: Static function parameter help
                jfb00 Community Member

                Gordon, Instead of Function I use Formatter and it works, thanks for your help!

                Best,