0 Replies Latest reply on Feb 25, 2010 6:37 AM by paromitadey

    Tree - Selected item on tree collapse --- erratic behavior

    paromitadey Level 1



      The code example given in http://www.adobe.com/devnet/flex/quickstart/working_with_tree/




      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" viewSourceURL="src/index.html">
                  import mx.collections.XMLListCollection;
                  private var company:XML =
                      <department title="Finance" code="200">
                          <employee name="John H"/>
                          <employee name="Sam K"/>
                      <department title="Operations" code="400">
                          <employee name="Bill C"/>
                          <employee name="Jill W"/>
                      <department title="Engineering" code="300">
                          <employee name="Erin M"/>
                          <employee name="Ann B"/>
                  private var companyData:XMLListCollection = new XMLListCollection(company.department);
                  private function treeLabel(item:Object):String
                      var node:XML = XML(item);
                      if( node.localName() == "department" )
                          return node.@title;
                          return node.@name;
                  private function addEmployee():void
                      var newNode:XML = <employee/>;
                      newNode.@name = empName.text;
                      var dept:XMLList =company.department.(@title == "Operations");
                      if( dept.length() > 0 ) {
                          empName.text = "";
                  private function removeEmployee():void
                      var node:XML = XML(tree.selectedItem);
                      if( node == null ) return;
                      if( node.localName() != "employee" ) return;
                      var children:XMLList = XMLList(node.parent()).children();
                      for(var i:Number=0; i < children.length(); i++) {
                          if( children[i].@name == node.@name ) {
                              delete children[i];
          <mx:Tree id="tree" top="72" left="50" dataProvider="{companyData}"
               height="224" width="179"/>
              <mx:Button label="Add Operations Employee" click="addEmployee()"/><mx:TextInput id="empName"/>
          <mx:Button label="Remove Selected Employee" click="removeEmployee()"/>    



      The Code snippet pasted above is from one of the Examples given in the URL mentioned above. The Results of the respective Examples are embedded within that page (mentioned URL). In all the embedded SWFs if a parent node is expanded and a child node is selected and then you close the expanded parent node to let it collapse and then again click on the parent node to expand it, it retains the selection of the child node that was previously selected. But strangely if you copy the same code or save the Zip file from the View source, which is enabled and try to run it from the Flex Builder locally, the examples run fine but the child node selection is not retained.


      I am unable to decipher the reason behind this difference in behavior of the same code snippet behaving in the Adobe devnet link and locally.

      Is there anything else that is being done which is missing in the example code snippets as given in the devnet site?


      Thanks and Regards,