Hi.
First of all my apoligise if this really isnt what your looking for, as
I have deleted the previous posts so havent read the whole discusion.
Hopefully this may help though. I have created a tree component that
loads in an xml structure, the xml structure can change i.e. new levesl
edded / removed and this is reflected in the tree. I think this is what
your looking for but like i say i may be totally wrong. I have attached
some code below.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
width="360"
height="500"
showFlexChrome="false"
applicationComplete="init()"
creationComplete="categoriesXML.send()">
<mx:HTTPService id="categoriesXML" url="data/categories1.xml"
resultFormat="e4x" />
<mx:Script>
<![CDATA[
private var selectedItem:String;
public function treeChangeEvent(event:Event):void
{
if (event.currenttarget.selectedit...@label)
{
selectedItem = " Selected Item " +
event.currenttarget.selectedit...@label;
trace(selectedItem);
}
}
]]>
</mx:Script>
<mx:Canvas id="categoriesListCanvas"
height="333"
width="338"
x="10"
y="112">
<mx:Tree id="categoriesTree"
change="treeChangeEvent(event);"
dataProvider="{categoriesXML.lastResult.category}"
labelField="@label"
x="0"
y="0"
width="338"
height="333"
backgroundColor="#111111"
backgroundAlpha="0.9"
borderColor="#000000"
color="#FFFFFF"
>
</mx:Tree>
</mx:Canvas>
</mx:WindowedApplication>
// categories1.xml
----------------------
<?xml version="1.0" encoding="utf-8"?>
<categories>
<category category="Adobe AIR"/>
<category category="Adobe Flex">
<category category="1">
<category category="1a"/>
<category category="1b"/>
<category category="1c"/>
<category category="1d"/>
<category category="1e"/>
<category category="1f"/>
</category>
<category category="2"/>
<category category="3"/>
<category category="4"/>
<category category="5">
<category category="5a"/>
<category category="5b"/>
<category category="5c"/>
<category category="5d"/>
<category category="5e"/>
<category category="5f"/>
</category>
<category category="6"/>
</category>
<category category="AS3"/>
<category category="PHP"/>
<category category="FlashLite">
<category category="FlashLitea"/>
<category category="FlashLiteb"/>
<category category="FlashLitec"/>
<category category="FlashLited"/>
<category category="FlashLitee"/>
<category category="FlashLitef"/>
</category>
<category category="Other"/>
</categories>
Barry.
Amy wrote:
>
> --- In [email protected]
> <mailto:flexcoders%40yahoogroups.com>, "timgerr" <tgallag...@...> wrote:
> >
> > Amy, as always, you rock, that url was a good read. My problem is I
> > am not sure how many children I will have or what the structure will
> > look like. I am doing a tree so I can have n number of nodes or
> > children, and I am not sure how to build the return object/array.
>
> Your app will probably perform better if you don't try to build the
> whole tree at once.
>
> But you might want to google on "recursion". Essentially, the
> principle is to use a function that works on an object in such a way
> that if the object has children, the function will call itself again
> for each child. That's not as difficult as it sounds, once you get
> your head around it--you just have to trust the recursion to do its
> thing and not force it. Probably someone has even posted some
> recursive PHP examples.
>
> Another way to approach it is to use the composite pattern and just
> populate the first level of objects, then once each object is
> instantiated it will start pulling down its own children and so on.
> This is sort of how I handle it, but I didn't make it where that
> always happens automatically so that if those resources are needed
> for something else the process can be interrupted.
>
> Oh, and one last thing...if your database technology isn't set in
> stone, you might want to consider using SQL Server, because Shape
> queries are made for this. AFAIK, other databases don't have
> anything that does this quite so nicely.
>
> HTH;
>
> Amy
>
>