Hi all,

I have a tree containing lots of branches.  When a user opens a 
branch I add a load of leaf nodes to it.  I am running into problems 
where the new nodes are not displayed correctly.

Here is a sample application which demonstrates the problem:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; width="200" 
height="300" layout="absolute" creationComplete="createTopNodes();">
  <mx:Script>
    <![CDATA[
      import mx.events.TreeEvent;
      import mx.collections.ArrayCollection;

      [Bindable] private var treeNodes:ArrayCollection = new 
ArrayCollection();

      private function createTopNodes():void
      {
        var newTestObj:TestObj;
        for (var i:int=1; i<=20; i++)
        {
          newTestObj = new TestObj();
          newTestObj.id = i.toString();
          newTestObj.children = new Array();
          treeNodes.addItem(newTestObj);
        }
      }

      private function itemOpenHandler(e:TreeEvent):void
      {
        var selectedObj:TestObj = TestObj(e.item);
        if (selectedObj.hasChildren)
        {
          return;
        }
        var newTestObj:TestObj;
        for (var i:int=1; i<=20; i++)
        {
          newTestObj = new TestObj();
          newTestObj.id = selectedObj.id + "_" + i.toString();
          newTestObj.children = new Array();
          selectedObj.children.push(newTestObj);
        }
        selectedObj.hasChildren = true;
      }
    ]]>
  </mx:Script>
  <mx:Tree id="testTree" width="100%" height="100%" 
dataProvider="{treeNodes}" labelField="id" itemOpen="itemOpenHandler
(event);"/>
</mx:Application>

This demo simply creates 20 top-level nodes and adds 20 child nodes 
whenever you open an existing node.

If you run the application and expand a node, the new child nodes are 
displayed down to the bottom of the visible tree area (all well and 
good).  However if you scroll down, the remaining sub-nodes are 
nowhere to be seen!  In fact, the visible sub-nodes have been drawn 
on top of the nodes at the top of the tree.  However if you close the 
node again and open it a second time everything is displayed as it 
should.

Is this a bug with the tree control or am I doing something 
completely wrong?  I need to create nodes like this on the fly as my 
tree is very big and I need to fetch child nodes from a database 
whenever the user opens a node in the tree.  I've tried adding calls 
to invalidateDisplayList and invalidateSize on the tree after 
creating the child nodes but this doesn't seem to make any difference.

Thanks,

Nick.

Reply via email to