0 Replies Latest reply on Jan 26, 2007 10:04 AM by Pigg_Man

    Help on Deleting Node in Tree?

    Pigg_Man
      I'm trying to delete a node on a tree and some weird stuff is occurring. Here is my code:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" initialize="init();" layout="absolute">
      <mx:Script>
      <![CDATA[

      private function click () : void {
      if (MyTree.selectedItems.length > 0) {
      var items:Array = MyTree.selectedItems;
      for (var i:int = 0; i < items.length; i++) {
      var nodeToDelete:XML = XML(items );
      var xlcParent:XMLListCollection = new XMLListCollection(nodeToDelete.parent().children());
      var iIndex:int = xlcParent.getItemIndex(nodeToDelete);
      xlcParent.removeItemAt(iIndex);
      }
      }
      }
      ]]>
      </mx:Script>
      <mx:XMLListCollection id="MyDP">
      <mx:XMLList>
      <root label="Default Policy">
      <node label="node1"/>
      <node label="node2"/>
      <node label="node3"/>
      <node label="node4"/>
      <node label="node5">
      <node label="node1"/>
      <node label="node2"/>
      <node label="node3"/>
      <node label="node4"/>
      <node label="node5">
      <node label="node1"/>
      <node label="node2"/>
      <node label="node3"/>
      <node label="node4"/>
      </node>
      </node>
      </root>
      </mx:XMLList>
      </mx:XMLListCollection>

      <mx:Tree labelField="@label" id="MyTree" dataProvider="{MyDP}" x="141" y="109" width="528" height="440"/>
      <mx:Button click="click();" x="141" y="557" label="Delete Selected Node"/>
      </mx:Application>


      For some reason when I expand all the nodes and try to delete one of the great grand children all of the great grand children shift over as if they are siblings of the node that I deleted the great grand children from.

      Anyone have some good ideas? I sure wish deletion of nodes was as easy as in actionscript 2.0