Thank you for your answer, i've finally solved the question, with some
work around!
Each node of my tree represents a level of an hierarchy, and when a
node is expanded, it is added to a datagrid as a column. The same
behavior applies when the node is closed - the item is removed from
the datagrid. Well my main issue was when i had several expanded
levels and collapsed the root element, or any other non leaf node. I
needed to access all the child node of the closed item, close them,
and remove each child from the grid.
Instead of the initial problem, i force the tree to collapse the
children of a collapsed node, so when the node is re-expanded, their
children are collapsed.
So:
1. On itemOpen, i created a handler on the TreeEvent event, like this:
private function openItem(evt:TreeEvent):void {
var descriptor:ITreeDataDescriptor = tree.dataDescriptor;
var cursor:IViewCursor;
var childItem:Object;
var childItems:Object;
if (evt.item == null){
return;
}
childItems = descriptor.getChildren(evt.item);
if (childItems){
cursor = childItems.createCursor();
while (!cursor.afterLast){
childItem = cursor.current;
var expanded:XML = new XML(childItem);
tree.expandItem(childItem,false,false);
addItemToDataGrid(expanded);
cursor.moveNext();
}
}
}
2. On itemClose, i created a handler on the TreeEvent event, like this:
private function closeItem(evt:TreeEvent):void {
var selected:XML = new XML(evt.item);
removeItemFromDataGrid(selected);
}
It turned out to be a simple solution, hope it is helpful to someone! :)
--- In [email protected], "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> You should be able to call expandItem regardless of the state of the
> children.
>
>
>
> ________________________________
>
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of vitorinomarlene
> Sent: Thursday, March 13, 2008 5:40 AM
> To: [email protected]
> Subject: [flexcoders] Tree ItemClose
>
>
>
> Hello,
> I'm trying to acomplish the following tree behavior:
> A tree node can only be closed if their children are leafs or if their
> children are closed. I've added handlers for itemClose, and through
> the event.item i can acces the node data (the xml data of the closed
> item), but i don't know how to check wether the corresponding tree
> node has children and if these children are open or closed. Thank you
> very much
>