3 Replies Latest reply on Aug 7, 2008 4:44 AM by Newsgroup_User

    Issue with using array as a function parameter

    BJWILD
      Im trying to create a functino that takes an array as a parameter and give it a default value of an empty array however im getting 1047: Parameter initializer is unknown with a number of ways I have tried.

      eg:

      public function foo( myArray:Array = [] ):void{
      // do stuff with the array
      }

      generated this error:
      1047: Parameter initializer unknown or is not a compile-time constant.

      using myArray:Array = new Array() gives the same error...


      Anyone else come across this?
        • 1. Re: Issue with using array as a function parameter
          Level 7

          "BJWILD" <webforumsuser@macromedia.com> wrote in message
          news:g7dqkq$bqn$1@forums.macromedia.com...
          > Im trying to create a functino that takes an array as a parameter and give
          > it a
          > default value of an empty array however im getting 1047: Parameter
          > initializer
          > is unknown with a number of ways I have tried.
          >
          > eg:
          >
          > public function foo( myArray:Array = [] ):void{
          > // do stuff with the array
          > }
          >
          > generated this error:
          > 1047: Parameter initializer unknown or is not a compile-time constant.
          >
          > using myArray:Array = new Array() gives the same error...
          >
          >
          > Anyone else come across this?

          try

          public function foo(myArray:Array=null):void{
          if (myArray==null){
          myArray=new Array();
          }
          }

          not sure why what you tried isn't working, but this is one way arround it...


          • 2. Issue with using array as a function parameter
            BJWILD Level 1
            Just got answer from Google Flex group...
            one possible answer is to initialitze it using the null value
            ie: myArray:Array = null
            • 3. Re: Issue with using array as a function parameter
              Level 7
              Glad you found that, since no one here was going to suggest that :-p

              "BJWILD" <webforumsuser@macromedia.com> wrote in message
              news:g7dtbe$ech$1@forums.macromedia.com...
              > Just got answer from Google Flex group...
              > one possible answer is to initialitze it using the null value