2 Replies Latest reply on Mar 7, 2007 5:44 AM by goingflex

    dynamic array declaration

    goingflex
      Hi
      This is a simple one but I need the corect way to declare arrays in a for loop. I need the correct syntax for creating 10 arrays for example named dp0 ..dp9.

      Thanks for your help.

      for (i=0;i<10;i++){
      var dp'i' Array= new Array; //This does not work,
      }
        • 1. dynamic array declaration
          Web et plus Level 1
          hello, this kind of syntax or something like this was never allowed
          var "dp"+i : Array
          var dp[ i ] : Array
          you can't create variables with dynamique name like this, the trick is to full an array (or an Object) with dynamical index (or propertie) :

          var dp : Array = new Array()
          var dp2 : Object = {}
          for (var i : int = 0 ; i<10 ; i++)
          {
          dp[ i ] = new Array(i,i*i);
          dp2[ i ]= new Array(i,i*i);
          //notice that you dont use 'var' and typing (' : Array') cause you only add dynamicly index or property you dont create var
          }
          • 2. Re: dynamic array declaration
            goingflex Level 1
            Got it. Thanks for your help tooy.