I would stick with what you know and used nested array collections. I
was about to implement this structure when I checked out flexcoders
and saw your post. This should help you out a bit:
1) make your array into a class.
package dto
{
import mx.collections.ArrayCollection;
[Bindable]
public class aArr
{
public var id:int=0;
public var description:String = "";
public var children:ArrayCollection = new ArrayCollection
public function aArr(obj:Object = null)
{
if (obj != null)
{
this.id = obj.id;
this.description = description.SD;
this.children = new ArrayCollection;
}
}
}
}
As you see you have to add an arraycollection to your class. This is
where your children will go.
2) Build your data from what ever your source is and put it in these
nested array collections. If i were to do these from a .net
webservice i would have it send over the data in a multidimensional
array. You can add the children to the correct parents with slick for
and if statements.
anyways, here is the code I would use to make a few layers(make sure
you put class above in a file named "aArr.as" in a folder named dto):
<?xml version="1.0" encoding="utf-8"?>
<mx:Application creationComplete="load()"
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import dto.*;
[Bindable]
public var treeArray:ArrayCollection = new ArrayCollection;
public function load():void{
var aArrItem1:aArr = new aArr()
aArrItem1.id = 0
aArrItem1.description = "Root Node 1"
var aArrItem2:aArr = new aArr()
aArrItem2.id = 0
aArrItem2.description = "child Node 1"
var aArrItem3:aArr = new aArr()
aArrItem3.id = 0
aArrItem3.description = "child Node 2"
var aArrItem4:aArr = new aArr()
aArrItem4.id = 0
aArrItem4.description = "Root Node 2"
aArrItem1.children.addItem(aArrItem2)
aArrItem2.children.addItem(aArrItem3)
treeArray.addItem(aArrItem1)
treeArray.addItem(aArrItem4)
}
]]>
</mx:Script>
<mx:Tree height="100%" width="100%" dataProvider="{treeArray}"
labelField="description" ></mx:Tree>
</mx:Application>
3) You can see that to add a child you do addItem(). You can also
specify where in the list you want to put the child with addItemAt().
I hope this helps. If you have problems getting ur array into this
nested array collection structure or finding out parents just reply
with a chunk of data and I'll show you how I would put it into this form.
-Nate
--- In [email protected], "Sal" <[EMAIL PROTECTED]> wrote:
>
> hi,
> i have an array of records received from an amfphp call and i need
> to fill a tree control with that data.
>
> the array has this format:
>
> aArr[0].id
> aArr[0].description
> aArr[0].parent
> aArr[0].order
>
> aArr[1].id
> aArr[1].description
> aArr[1].parent
> aArr[1].order
>
> ... and so on
>
> i didn't find any method of the control that adds node or that sets
> node parent.
>
> Any ideas?
>
> Thanks.
>