0 Replies Latest reply on Mar 11, 2008 7:40 AM by vzwhaley

    adding a node to drag and drop tree control

    vzwhaley
      Hello all! I am wanting to add a branch node to a drag and drop tree control based on the item that is being dragged. For example, in the following XML code, if I drag page aname="02 "to the drag and drop tree control, I would like for the tree control to automatically create a branch node with the pubDate, so that it would be a branch node with the pubDate and a leaf node with the page aname. I am successfully adding page anames to the drag and drop tree control, so that part is working, but I would like to add the branch node with the pubDate and have the pages fall under that node as leaves.

      EXAMPLE XML:

      <tearsheets>
      <pubDate aname="Tuesday, March 11, 2008">
      <section aname="A">
      <page aname="02" date="20080311" sectionID="A" image="tearsheets/2008/03/11/jpg/20080311_A_02.jpg" pdf="tearsheets/2008/03/11/pdf/20080311_A_02.pdf"/>
      <page aname="03" date="20080311" sectionID="A" image="tearsheets/2008/03/11/jpg/20080311_A_03.jpg" pdf="tearsheets/2008/03/11/pdf/20080311_A_03.pdf"/>
      <page aname="04" date="20080311" sectionID="A" image="tearsheets/2008/03/11/jpg/20080311_A_04.jpg" pdf="tearsheets/2008/03/11/pdf/20080311_A_04.pdf"/>
      </section>
      <section aname="B">
      <page aname="01" date="20080311" sectionID="B" image="tearsheets/2008/03/11/jpg/20080311_B_01.jpg" pdf="tearsheets/2008/03/11/pdf/20080311_B_01.pdf"/>
      <page aname="02" date="20080311" sectionID="B" image="tearsheets/2008/03/11/jpg/20080311_B_02.jpg" pdf="tearsheets/2008/03/11/pdf/20080311_B_02.pdf"/>
      </pubDate>
      </tearsheets>

      HERE IS A PORTION OF THE CODE FROM MY PROJECT THAT IS OPERATING THE DRAG AND DROP TREE CONTROL:

      public var listDP:XMLListCollection = new XMLListCollection(new XMLList());

      public function dragDropHandler(event:DragEvent):void {
      if (event.dragSource.hasFormat("items"))
      {
      // Explicitly handle the dragDrop event.
      event.preventDefault();

      // Since you are explicitly handling the dragDrop event,
      // call hideDropFeedback(event) to have the drop target
      // hide the drop indicator.
      // The drop indicator is created
      // automatically for the list controls by the built-in
      // event handler for the dragOver event.
      event.currentTarget.hideDropFeedback(event);

      // Get drop target.
      var dropTarget:Tree=Tree(event.currentTarget);

      // Get the dragged item from the drag initiator.
      // The List control always writes an Array
      // to the dragSource object,
      // even if there is only one item being dragged.
      var itemsArray:Array =
      event.dragSource.dataForFormat("items") as Array;

      // Copy the dragged data into a new Object.
      var tempItem:Object =
      {label: itemsArray[0].label, data: itemsArray[0].data};

      // Get the drop location in the destination.
      var dropLoc:int = dropTarget.calculateDropIndex(event);

      // Add the new object to the drop target.
      IList(dropTarget.dataProvider).addItemAt(tempItem, dropLoc);
      }
      }

      <mx:Tree id="myTearsheets2"

      dataProvider="{listDP}"

      labelField="@aname"

      dragDrop="dragDropHandler(event);"

      width="100%"

      height="100%"

      borderThickness="0"

      dropEnabled="true"

      />

      Any ideas would be appreciated!