2 Replies Latest reply on May 15, 2009 12:45 AM by seiza13

    making tree using recursion




      well, i have some troubles when i copy folders recursively between trees.

      for example if i click on a folder of my tree_1 i want to copy this folder and its fathers






           - C.1

           - C.2


      when i click on folder "C"










      can anyone show me some example?



        • 1. Re: making tree using recursion
          _Natasha_ Level 4



          as a very quick example using XML as a dataProvider.

          Note, that you should use XMLListCollection or ArrayCollection to store your data to show changing data. If you use other arrays you should manually change tree.dataProvider = tree.dataProvider to show changes, but all nodes closed so it will be unable to open the tree.


          Hope it's helpful.


          <?xml version="1.0" encoding="utf-8"?>

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">


          <mx:State name="alerting">

          <mx:AddChild relativeTo="{newView}" position="before">

          <mx:Label text="hehe"/>






          import mx.utils.ObjectUtil;

          import mx.events.TreeEvent;

          import mx.controls.Alert;


          private var n:int = 1;

          private function onItemOpen(event:TreeEvent):void


          var newItem:XML;


          var itemData:XML = event.item as XML;

          newItem = ObjectUtil.copy(itemData) as XML;

          newItem.@label = newItem.@label + " " + n.toString();

          delete newItem.*; // delete all childs

          var parent:XML = itemData.parent();

          while (parent.childIndex() != -1) // root has -1


          var addNode:XML = ObjectUtil.copy(parent) as XML;

          delete addNode.*;

          addNode.@label = addNode.@label + " " + n.toString(); // add id


          newItem = addNode;

          parent = parent.parent();










          <mx:XMLListCollection id="tstData">


          <mx:XMLList xmlns="">


          <item label="Level1">

          <item label="Level2">

          <item label="Level3">

          <item label="Level4">

          <item label="level5"/>









          <mx:HBox x="0" y="0" width="100%" height="100%">

          <mx:Tree id="oldView" width="50%" height="100%" showRoot="false" dataProvider="{tstData}" labelField="@label" itemOpen="onItemOpen(event)">




          1 person found this helpful
          • 2. Re: making tree using recursion
            seiza13 Level 1

            Hi Natacha!

            your example helped me very much

            Thank you a lot!