Just to make a correction:
xmlFontes.refresh; wasn't doing anything so I removed it... It refreshed beacuse when I make changes I call the xml again and rebuild the tree. But I need to know when the tree ends rebuilding so I can open the node that was previously selected.
I really dont understand your problem.
I work with dynamic extended tree controls and dynamic XMLList data in my application, so I can probably help you a bit.
how exactly do you "rebuild" the tree? I think that will explain how you can reset the tree node selection...
Well... I don't know if I can explain mutch better... My english is not great!
I'm using a SpringLoadedTree, that I believe is some kind of tree but with more functions.
When my application initializes it makes this:
<mx:HTTPService id="treeF" showBusyCursor="true" url="php/treeFontes.php" resultFormat="e4x" result="onResultFontes(event)" />
My treeFontes.php file queries a sql database and gives back some xml code. And then:
xmlFontes = XML(event.result);
And xmlFontes is the dataProvider of my tree. This tree I'm using lets me drag and drop items between the tree nodes. When I do that I call another HTTPService to update the node position on the database. When it finishes updating the database I call the <mx:HTTPService id="treeF"... again and it updates the tree.
What I wanted to do is this:
When I drag the node on the tree I save that nodes parent id and when I drop it I save the new parent node id - confusing. With this I was hopping to be able to open the tree nodes from where I dragged and droped the child node. I can do this, but only with the click of a button...
In my onResultFontes function I call another function that does what I want, but it's not working, beacause I don't know if it has finished generating the tree, and it probably tries to open the nodes before they are created.
The function to open the nodes previously opened does something like this:
expandParents(node); - This is the original node - saved on drag
expandParents(node); - This is the destination node - saved on drop
It's quite confusing... But I can't think of a better way.
Thanks and sorry for all the confusing explanation!
Your English is fine. Do not apologize for your English! You did fine explaining your problem, good job.
I think what you need to do is re-set the selected node in your result event, which would be: OnResult.
Do you have that function available to you? If so, you need to obtain the tree's open node ID (before the XML refresh happens) and then re-apply that at the end of OnResult.
Hopefully that helps?
That's what I'm doing. I have the function to open the nodes in the result function, but it seems to me that it calls that function before it ends loading all the data in the tree... If I call the function from a button it opens the nodes correctly - maybe beacause of the delay of moving the mouse, and clicking it.
I believe my problem is related with the fact that I populate(?) the tree in the result function. I call the httpservice and then, on result I do this xmlFontes = XML(event.result); and then I immediatly call the function to open the nodes. Is there a way to know if the tree has ended beeing filled?
Thanks again for your help!
^ That's strange, I would think it would work...maybe the XML is very large?
Maybe try using the creationComplete attribute of the tree control. You can specify a function for "creationComplete" and set the open node there. Give it a try....
Tried what you said, but it didn't work... I believe the creationComplete handler, only runs when the tree is first created...
Anyway, thank's for the help...