1 Reply Latest reply on Feb 24, 2009 10:14 PM by Tariq Ahmed [ACP]

    Is this a bug: ModelLocator.ArrayCollection.length

    freelanceDesignDeveloper
      ModelLocator.ArrayCollection.length that equals to 4 starting from index 0 (zero)
      I see:
      going into the objects using for each item i see correctly:
      item:[object Object]
      item:[object Object]
      item:[object Object]
      item:[object Object]

      going into the objects using for loop with ModelLocator.ArrayCollection.length, it is not counting the full length:
      0 --this is page:springgraph16.UIComponent0.template1 with index:0 and pageid:1
      1 --this is page:springgraph16.UIComponent0.template2 with index:1 and pageid:2
      2 --this is page:springgraph16.UIComponent0.template3 with index:2 and pageid:3

      If I index into ModelLocator.ArrayCollection[3] in the for loop I get errors.

      example:
      checked the length with:
      trace("---lenbefore:" + __modelLocator.siteRef.length); // displays a trace, ---lenbefore:3
      __modelLocator.siteRef.addItem(templatesAllData);
      trace("---lenafter:" + __modelLocator.siteRef.length) // displays a trace, ---lenafter:4

      THIS WORKS AND DISPLAYS 4 ITEMS:
      for each (var item:* in __modelLocator.siteRef){
      trace("item:" + item);
      }
      trace result is:
      item:[object Object]
      item:[object Object]
      item:[object Object]
      item:[object Object]

      THIS DOES NOT WORK:
      for(s =0 ; s < __modelLocator.siteRef.length; s++){
      trace(s +" --this is page:" + __modelLocator.siteRef[s]['template']);
      trace("CHECK:" +__modelLocator.siteRef[3]['template']); // this thoughts up an error below:
      }

      ERROR: RangeError: Index '3' specified is out of bounds.
      which is why these do not work in the for loop:
      for(s =0 ; s <= __modelLocator.siteRef.length; s++)
      for(s =0 ; s < __modelLocator.siteRef.length+1; s++)
        • 1. Re: Is this a bug: ModelLocator.ArrayCollection.length
          Tariq Ahmed [ACP] Level 1
          If you use the debugger and step through the ArrayCollection as it does each loop - what does the watch variables panel show?

          This shouldn't make a difference, but out of curiosity - after the AC has all it's day, if you make a copy of it and then loop over it... what happens...? E.g.:

          __modelLocator.siteRef.addItem(templatesAllData);
          var newAC : ArrayCollection = ObjectUtil.copy(__modelLocator.siteRef);

          for(s =0 ; s < newAC.length; s++)
          {
          ....
          }

          Or another idea... instead of accessing the AC via index (e.g. siteRef[s]), what if in the loop you do a getItemAt(s)?