1 Reply Latest reply on Jun 15, 2009 10:38 PM by Flex harUI

    Pass variable length arguments to another variable length arguments

    zhpingw Level 2

      Can't pass a variable length argument to another variable length argument

       

      For example

       

      public function call(name:String, ... params):Object

      {

        ExternalInterface.call(name, params);
      }

       

      call("test", "param1");

       

      The "param1" is treated as one argument with array type in the second "call" function, but what I want is it treate it as an argument as string.

       

      The result is:

       

      <invoke name="test" returntype="xml"><arguments><array><property id="0"><string>name</string></property></array></arguments></invoke>

       

      But what I want is

       

      <invoke name="test" returntype="xml"><arguments><string>name</string></arguments></invoke>

       

      So I have to do is:

       

      public function call(name:String, ... params):Object

      {

        if (params.length == 1)

        {

            ExternalInterface.call(name, params[0]);

        }else if (params.length == 2)

      {

          ExternalInterface.call(name, params[0], params[1]);

      }else if (params.length == 3)

      {

          ExternalInterface.call(name, params[0], params[1], params[2]);

      }else

          throw new Error("I'm crazy");

      }

       

      This is terrible solution, if there any workaround?

       

      The compiler should can handle this situation.