I'm maintaining a large legacy Flex 4.6 project which refuses to die and have run into an issue with the Mx Tree component that I have not been able to solve. The gist is that adding items to an existing node exhibits weird behavior if the items are duplicates. If the node is created with unique items the component behaves as expected.
For example, the image below shows the result of adding the file "AAAAA.png" multiple times to the existing node. The highlighting goes berserk and the component seems to get confused about how many items it has (have tested this).
I've tried the "refresh tree" hack (below) of resetting the data provider, etc. and I call refresh on the various backing Array Collections. I started to go down the road of replacing the Mx Tree with a Spark Tree that someone came up with but it was turning into too much time.
Before I tell the client to let go of this feature, does anyone have a thought about what the issue might be? I am more of an Actionscript than a Flex developer and don't know my way around components beyond just using them.
protected function vfAddToBtn_clickHandler(event:MouseEvent):void
{
if (virtualFoldersList.selectedItem == null){
Alert.show("Please select a virtual folder to add to", "Add to Virtual Folder", Alert.OK);
} else {
if (briefcaseData.currentSelectionsList.length > 0){
var vf:VirtualFolder = virtualFoldersList.selectedItem as VirtualFolder;
if (vf != null){
vf.children.addAll(briefcaseData.currentSelectionsList);
vf.children.refresh();
briefcaseData.virtualFoldersArray.refresh();
refreshTree(virtualFoldersList);
} else {
trace("ERROR: vfAddToBtn_clickHandler vf is null");
}
}
}
}
private function refreshTree(tree:Tree) : void
{
var selectedIndex : int = tree.selectedIndex;
var openItems : Object = tree.openItems;
tree.dataProvider = tree.dataProvider;
tree.openItems = openItems;
tree.validateNow();
tree.selectedIndex = selectedIndex;
}

And the answer is...that the Mx Flex Tree from Flex 4.6 is just broken. I have tried everything, even creating a new
ArrayCollectionfrom the source arrays of the twoArrayCollectionsI was trying to merge (the code below). The result is the same: if there is a duplicate item, then the rollover item highlighting in the component is wrong and the component becomes confused about how many items it contains.Oh well.