2 Replies Latest reply on Oct 4, 2007 8:55 AM by camfieldaj

    declaring an array

      All I am trying to do is to create an array within a loop. Here is the code I am using for the purpose, but its giving me errors:

      var node:Array = new Array();
      for (var i:uint = 0; i < pagedInventory.length; i++)
      var node :ExampleData = new ExampleData("a", "b", "c","d", "e","f", 0);

      1086: Syntax error: expecting semicolon before leftbracket.
        • 1. Re: declaring an array
          Gregory Lafrance Level 6
          You would have to post more complete code to understand why you got the error you did, but below is code that works for me. Here are two ways to create arrays:

          var myArray:Array = new Array("a", "b", "c","d", "e","f", 0);
          var myArray2:Array = ["a", "b", "c","d", "e","f", 0];

          ----------------- more complete code below -----------------
          <?xml version="1.0"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
          width="600" height="600" creationComplete="init()">
          private function init():void{
          var node:Array = new Array();
          for (var i:uint = 0; i < 10; i++)
          var myArray:Array = new Array("a", "b", "c","d", "e","f", 0);
          • 2. Re: declaring an array
            In case you haven't figured it out yet: you're declaring node as an Array, then in the loop you're redeclaring node as some nonexistant type ExampleData. That wouldn't even work in Ruby. :}