Search code examples
xmlapache-flextreeinsertion

flex: move item around in a tree control


I have a tree control and I want to give the user the ability that he can move up and down the element he just selected with a up and a downbutton. The tree gets generated from XML.

I managed to insert the selected item a second time at a other place, with the following code:

var parentXML:XML = XML(containerTree.selectedItem).parent();

var upperItem:XML = topContainer.source[containerTree.selectedIndex-1]; 

parentXML.insertChildBefore(upperItem,XML(containerTree.selectedItem));

but then I have the item there twice in the List. How can I remove to reinsert it?

Thanks for Hints! Markus


Solution

  • Use the delete (XML) operator to remove XML nodes.

    var parentXML:XML = XML(containerTree.selectedItem).parent();
    
    var upperItem:XML = topContainer.source[containerTree.selectedIndex-1]; 
    
    delete containerTree.selectedItem;
    
    parentXML.insertChildBefore(upperItem,XML(containerTree.selectedItem));