You could also use nested Array and Object literal syntax to do this in
one statement:
myTree.dataProvider =
[
{ label: "Top level", children:
[
{ label: "First" },
{ label: "Second" }
]
},
{ label: "Another top level" }
];
When you set the dataProvider do an Array, it gets converted to an
ArrayCollection automatically.
- Gordon
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Matt
Sent: Thursday, May 17, 2007 1:47 PM
To: [email protected]
Subject: [flexcoders] Re: Trees and ActionScript
As is usually the case, I spend all my time trying to figure out the
solution to the problem and then finally give up and post a message.
Then five minutes later I figure out the solution. ;)
Here's an example:
obj = new Tree();
dataProvider = new ArrayCollection();
var o1:Object = new Object();
o1.label = 'Top Level';
dataProvider.addItem(o1);
var o1a:ArrayCollection = new ArrayCollection();
o1.children = o1a;
var o1a1:Object = new Object();
o1a1.label = 'First';
o1a.addItem(o1a1);
var o1a2:Object = new Object();
o1a2.label = 'Second';
o1a.addItem(o1a2);
var o2:Object = new Object();
o2.label = 'Another top level';
dataProvider.addItem(o2);
obj['dataProvider'] = dataProvider;
Hope that helps someone some day. ;)
--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "Matt" <[EMAIL PROTECTED]> wrote:
>
> I am trying to programmatically build and manipulate a Tree entirely
> in ActionScript and I'm having serious issues doing so.
>
> I've tried various ways of doing it but currently my failed code looks
> like:
>
> var t:Tree = new Tree();
> var dp:XMLListCollection = new XMLListCollection();
> var o1:XML = <node label='Testing'/>;
> dp.addItem(o1);
> t.dataProvider = dp;
>
> Ideally I'd like to use only Objects. I've been able to make it work
> thus far by just having a dataProvider as ArrayCollection and adding
> Objects to it, but then I have no way of adding branches and I end up
> with a 1-deep tree.
>
> Any advice or references are appreciated. I've gone through the
> flexdocs and they offer a few examples that seem to almost be talking
> about what I'm trying to do, but they don't work.
>