0

I have an ArrayCollection with following structure (when viewed in debug mode):

[0]
- [0]
-- src
- [1]
-- src

src is the path to an image.

I need to get all of the src's out of the arraycollection. However because of the first (unnamed) node I can't take them in.

I've tried ArrayCollection[0].children and save the result in another ArrayCollection, however the new ArrayCollection has 2 Objects in it but no 'src'. There are just 2 null objects

firstArrayCollection is filled with the data as described above.

secondArrayCollection.addItem(firstArrayCollection[0].children);

when viewing the content of secondArrayCollection i see following structure (and data):

[0] null
[1] null
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jozzeh
  • 841
  • 10
  • 28

1 Answers1

2

try

var i:int = 0;
var myNormalArray:Array = new Array();

//loop through collection
for each (var child:* in myArrayCollection)
{
  //do what you want with the child
  myNormalArray[i++] = child;
}

This will get all of the objects out of the collection into a normal array where they can be refered by their index. If you look at an array collection it has no concept of length so the index cannot be a index it has to be a key.

or just do this thinking about it (although i've never done it)

var myArray:Array = myArrayCollection.toArray();

hope this helps

Jon

//********************************************************

Second Attempt !!!!!!

var pathArray:Array = new Array();
var i:int = 0;
for each (var child:* in myArrayCollection)
{
  for each (var pathObject:Object in child)
  {
    pathArray[i++] = pathObject.src;
  }
}

this should work, i haven't test it though

Jon
  • 4,295
  • 6
  • 47
  • 56
  • thx for your quick response. I tried both of them but I just get an Array with the same structure as the ArrayCollection. So the first [0] node is still blocking me to use it as a dataprovider – Jozzeh Aug 12 '09 at 20:24
  • are they object with a proeprty of src or just a string with the source in or a associative array with src as the key and the path as the value? – Jon Aug 12 '09 at 20:45
  • this image might make it a bit easier: http://img11.imageshack.us/img11/7578/afbeelding1k.png i need the data that resides under src (img/images/rekske.png <- example, the real app will have variable images) – Jozzeh Aug 12 '09 at 21:12
  • The array contains only the src's towards the images, so thumbs up. But now I wonder how I can use that array as an dataprovider for a tilelist with itemrenderer. doesn't seem to work... anyway, thx for your help – Jozzeh Aug 12 '09 at 22:08