adam
adam

Reputation: 22587

Flex - How to get Tree itemClick event to mimic itemOpen event?

I am using a Tree control with an XMLListContainer dataProvider.... I use an itemOpen event with the following code to update another data provider when a tree folder is opened (using small triangle) - the data provider contains all the <slide /> elements in that particular tree folder...

private function itemOpenEvent(event:TreeEvent):void {          
 slideDP = new XMLListCollection(event.item.elements("slide"));  
 slideDP.refresh();                     
}

If a second folder is opened thumbDP updates fine but when the first folder (or another closed folder) is clicked I want the same behaviour to happen (currently you have to close and reopen the first folder)

So I use a itemClick event - but this fires a ListEvent and I can't work out how to get the child elements from the XMLListContainer as easy... The code below throws an out of bounds exception

private function itemClickEvent(event:ListEvent):void {         
 treeFeed.getItemAt(event.rowIndex);                        
}

Can anyone help? Thanks :)

Upvotes: 1

Views: 5623

Answers (1)

Eric Belair
Eric Belair

Reputation: 10692

I would change your event listener to listen for a change Event, and use the selectedItem property of the Tree:

private function changeHandler(event:ListEvent):void
{                  
    slideDP = new XMLListCollection(tree.selectedItem.elements("slide"));

    slideDP.refresh();                           
}

You may need to cast selectedItem as XML or XMLList.

Upvotes: 2

Related Questions