0

I have tried adding an object to an ArrayCollection inside an ArrayCollection and it isn't working. I am getting Error #1009 with the following implementation:

for (var x:Number = 0; x < identifyArrayCollection.length; x++)
{
    identifyArrayCollection[x].speedsArrayCollection.addItem(speedsObj);
}

I can add the speedsObj to an ArrayCollection that is not inside an ArrayCollection.

Any help would be appreciated.

Thanks,

Mark

3 Answers3

0

The following code adds the item speedObj to the ArrayCollection found at index x of the ArrayCollection called identifyArrayCollection.

identifyArrayCollection.getItemAt(x).addItem(speedsObj);

Is this what you're looking for?


The code you have does the following:

identifyArrayCollection[x] 
//accesses the item stored in identifyArrayCollection 
//with the key of the current value of x
//NOT the item stored at index x

.speedsArrayCollection
//accesses the speedsArrayCollection field of the object
//returned from identifyArrayCollection[x]

.addItem(speedsObj)
//this part is "right", add the item speedsObj to the
//ArrayCollection
Sam DeHaan
  • 10,246
  • 2
  • 40
  • 48
0

Assuming that identifyArrayCollection is an ArrayCollection containing some Objects and speedsArrayCollection is an ArrayCollection defined as variable of the Object type that are contained in the identifyArrayCollection

you should do:

for (var x:Number = 0; x < identifyArrayCollection.length; x++)
{
    identifyArrayCollection.getItemAt(x).speedsArrayCollection.addItem(speedsObj);
}
Marcx
  • 6,806
  • 5
  • 46
  • 69
0

Don't forget that any compound object needs to be initialized as such first. For example (assuming initial run):

there is two ways you can do this: piggy-backing of @Sam

for (var x:Number = 0; x < identifyArrayCollection.length; x++)
{
   if (!identifyArrayCollection[x]) identifyArrayCollection[x] = new ArrayCollection();
   identifyArrayCollection[x].addItem(speedsObj);
}

or using an anonymous object if you really want to use explicit naming conventions - however be aware these are NOT compile time checked (nor is anything using the array accessor):

for (var x:Number = 0; x < identifyArrayCollection.length; x++)
{
   if (!identifyArrayCollection[x]) 
   {
      var o:Object = {};
          o.speedsArrayCollection = new ArrayCollection();
      identifyArrayCollection[x] = o;
   }
   identifyArrayCollection[x].speedsArrayCollection.addItem(speedsObj);
}
Mike Petty
  • 949
  • 6
  • 6