2 Replies Latest reply on May 26, 2006 7:24 AM by mikiM

    Cannot resolve attribute 'treeDataDescriptor' for component type mx.controls.Tree.

    mikiM Level 1
      Hi,

      I'm trying to compile an example from the documentation:
      I have two files :

      treeEx1.mxml

      <?xml version="1.0" encoding="iso-8859-1"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="initCollections()">

      <mx:Script>
      <![CDATA[
      import mx.collections.*;
      import mx.controls.treeClasses.*;
      import customComp.MyCustomTreeDataDescriptor;
      //Variables used to construct the ArrayCollection data provider
      //First top-level node and its children.
      public var nestArray1:Object = [
      {label:"item1", children: [
      {label:"item1 child", children: [
      {label:"item 1 child child", data:"child data"}
      ]}
      ]}
      ];
      //Second top-level node and its children.
      public var nestArray2:Object = [
      {label:"item2", children: [
      {label:"item2 child", children: [
      {label:"item 2 child child", data:"child data"}
      ]}
      ]}
      ];
      //Second top-level node and its children.
      public var nestArray3:Object = [
      {label:"item3", children: [
      {label:"item3 child", children: [
      {label:"item 3 child child", data:"child data"}
      ]}
      ]}
      ];
      //Variable for the tree array.
      public var treeArray:Object
      //Variables for the three Array collections that correspond to the
      //top-level nodes.
      public var col1:ArrayCollection;
      public var col2:ArrayCollection;
      public var col3:ArrayCollection;
      //Variable for the ArrayCollection used as the Tree data provider.
      [Bindable]
      public var ac:ArrayCollection;

      //build the ac ArrayCollection from its parts.
      public function initCollections():void{
      // Wrap each top-level node in an ArrayCollection.
      col1 = new ArrayCollection(nestArray1);
      col2 = new ArrayCollection(nestArray2);
      col3 = new ArrayCollection(nestArray3);
      // Put the three top-level node ArrayCollections in the treeArray.
      treeArray = [
      {label:"first thing", children: col1},
      {label:"second thing", children: col2},
      {label:"third thing", children: col3},
      ];
      //Wrap the treeArray in an ArrayCollection.
      ac = new ArrayCollection(treeArray);
      }

      // Adds a child node as the first child of the selected node,
      // if any. The default selectedNode is null, which causes the
      // data descriptor addChild method to add it as the first child
      // of the ac ArrayCollection.
      public function clickAddChildren():void {
      var newChild:Object = new Object();
      newChild.label = "New Child";
      newChild.children = new ArrayCollection();
      tree.treeDataDescriptor.addChildAt(tree.selectedNode, newChild, 0, ac);
      }

      ]]>
      </mx:Script>

      <mx:Tree width="200" id="tree" dataProvider="{ac}"
      treeDataDescriptor="{new MyCustomTreeDataDescriptor()}"/>
      <mx:Button label="add children" click="clickAddChildren()"/>
      </mx:Application>

      and
      and MyCustomTreeDataDescriptor.as :


      package customComp.MyCustomTreeDataDescriptor
      {
      import mx.collections.ICollectionView;
      import mx.collections.IViewCursor;
      import mx.events.TreeModelChangedEvent;
      import mx.events.TreeModelChangedEventDetail;
      import mx.controls.treeClasses.*;

      public class MyCustomTreeDataDescriptor implements ITreeDataDescriptor
      {

      // The getChildren method requires the node to be an Object
      // with a children field.
      // If the field contains an ArrayCollection, it returns the field
      // Otherwise, it wraps the field in an ArrayCollection.
      public function getChildren(node:Object,
      model:Object=null):ICollectionView
      {
      try
      {
      if (node is Object)
      {

      if(node.children is ArrayCollection){
      return node.children;
      }else{
      return new ArrayCollection(node.children);
      }
      }
      }
      catch (e:Error)
      {
      trace("[Descriptor] exception checking for getChildren");

      }
      return null;
      }

      // The isBranch method simply returns true if the node is an
      // Object with a children field.
      // It does not support empty branches, but does support null children
      // fields.
      public function isBranch(node:Object, model:Object=null):Boolean
      {
      try
      {
      if (node is Object)
      {
      if (node.children != null)
      {
      return true;
      }
      }
      }
      catch (e:Error)
      {
      trace("[Descriptor] exception checking for isBranch");
      }
      return false;
      }

      // The getData method simply returns the node as an Object.
      public function getData(node:Object, model:Object=null):Object
      {
      try
      {
      return Object(node);
      }
      catch (e:Error)
      {
      }
      return null;
      }

      // The addChildAt method does the following:
      // If the node parameter is null or undefined, inserts
      // the child parameter as the first child of the model parameter.
      // If the node parameter is an Object and has a children field,
      // adds the child parameter to it at the index parameter location.
      // It does not add a child to a terminal node if it does not have
      // a children field.
      public function addChildAt(node:Object, child:Object, index:int, model:Object=null):Boolean
      {
      var event:TreeModelChangedEvent = new TreeModelChangedEvent("modelChanged", false, false, TreeModelChangedEventDetail.ADD_NODE, child, node, index);

      if (!node)
      {
      var iterator:IViewCursor = model.createCursor();
      iterator.seek(CursorBookmark.FIRST, index);
      iterator.insert(child);
      }
      else if (node is Object)
      {
      if (node.children != null)
      {
      if(node.children is ArrayCollection) {
      node.children.addItemAt(child, index);
      if (model){
      model.dispatchEvent(event);
      model.itemUpdated(node);
      }
      return true;
      }
      else {
      node.children.splice(index, 0, child);
      if (model)
      model.dispatchEvent(event);
      return true;
      }
      }
      }
      return false;
      }

      }
      }

      I have read the docs and looked through some example on this form but I still can't figure it out .

      Thanks

      The code above is from:
      http://127.0.0.1:56812/help/topic/com.adobe.flexbuilder.help/html/Part2_DevApps.html
      Using hierarchical data providers