Posts tagged ‘xml’
There are plenty examples out there on how to add and remove leaf nodes from a Tree control at run time, one of my favorite is Working with tree controls tutorial by Adobe.
Now it’s time to learn more advanced stuff: auto select for new created item. This would be very easy to accomplish with List control. You would probably use ArrayCollection as a dataProvider, call addItem(item:Object), keep track of that item index, and then use list.selectedIndex = index.
Unfortunately this is not easy with Tree control. Tree control could have opened and closed nodes. If the nodes in the tree control are collapsed, the selectedIndex is different than when all the nodes are expanded. Instead of using selectedIndex you want to loop through all nodes to find a new item’s index.