2 Replies Latest reply on Dec 4, 2011 10:01 AM by Filmzaddict

    Invalidating Tree




      I am using the mx Tree control with a custom model, so i have also written custom class implementing ITreeDataDescriptor (also renderer but its just different icons than default ones). When i bind my model to the Tree, and also specify the descriptor and the data is displayed without problems, but this is already prepared data. When the user clicks on one of the nodes to expand it, i send a request to the server which returns a response and only then i add new children to the children property of the node that was clicked. The node itself was drawn as if it was expanded but nothing was actually underneath it, unless i clicked the node to close and then open again, and then the content was there. I wanted the tree to update automatially so i added an event listener to my onDataReceived method which would be called when server returned children data. and inside it i called tree.InvalidateList(); this worked, when i clicked a node the node would expand and with a slight delay (server) it showed its children. But the problem now is, when i scroll the tree with mousewheel or sidebar slider, the items start jumping from one node to another like crazy, things only return to normal if i open/close the node that was updated, same as before i added Invalidate list. Also, the sidebar vertical scroller of the tree is never in sync with the amount of content the tree is displaying.


      What is so special that happens when you close/open the node again??


      I tried adding different invalidation methods into the handler but it makes no difference:


      protected function onMenuChanged(event:Event):void









      Since the ItreeDatadescriptor interface has an AddNode method... should i somehow add new items through this method? because now everything happened from inside my model, i thought binding model to the tree would take care of it.


      What about ITreeDataDescriptor2 interface, how is it different?


      And one more question... I cant seem to make rows of the tree without vertical gap between them. I ve set padding bottom/top on the tree itself to 0, and i ve set the height of renderer to 16 like the size of the icon (tree renderer has no padding settings) but theres still always a gap present. How to remove this gap?

        • 1. Re: Invalidating Tree
          Filmzaddict Level 1

          I found a workaround for the first problem. It seems Tree has problems if you expand a node and then some time later you add children to it. So what i did i created a custom TreeItemRenderer inside which i removed the disclosureGroup (but kept the image inside it), doing this, i stopped the default behavior of the tree node to expand children... instead... when this image is clicked i send a request to the server, retrieve the data, process it, and then dispatch an event to view that the data is ready. Inside the handler for this event i open the coresponding tree node and everything works fine (scrollbar, scrolling, etc.)


          To answer my second question... ITreeDataDescriptor2 simply add 3 additional methods to ITreeDataDescriptor.


          Still working on "closing the gap"

          • 2. Re: Invalidating Tree
            Filmzaddict Level 1

            I guess i need new glasses. The gap between items wasnt really a gap, but rather default setting of rowHeight property which was set to 20.








            ...did the trick