views:

1000

answers:

1

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
+2  A: 

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
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
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
this image might make it a bit easier:http://img11.imageshack.us/img11/7578/afbeelding1k.pngi need the data that resides under src (img/images/rekske.png <- example, the real app will have variable images)
Jozzeh
I've update my original anwser
Jon
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. <mx:TileList id="dtGrid" dataProvider="{pathArray}"> <mx:itemRenderer> <mx:Component> <mx:Image source="{data}"/> </mx:Component> </mx:itemRenderer></mx:TileList>doesn't seem to work... anyway, thx for your help
Jozzeh