11 Replies Latest reply on Jan 16, 2007 7:14 AM by danFromBAH

    How to force repaint/render of mx:Tree

      Hello all:

      I am using an mx:Tree that gets populated dynamically from an mx:HTTPservice. When the new nodes are added I don't see the scroll bar change/move the reflect the exapnsion of the tree.

      Is there a way to force a tree to render itself? I have tried tree.invalidateList() and then tree.validateNow() ....

        • 1. Re: How to force repaint/render of mx:Tree
          ntsiii Level 3
          Well, re-assigning the dataProvider should always force the tree to re-render.

          But that is surgery with a meat cleaver.

          Are you appending nodes to the dataprovider? What is the dataProvider? what is the resultFormat?

          • 2. Re: How to force repaint/render of mx:Tree
            danFromBAH Level 1
            Yes, I am appending to the data provider at runtime and my result format is e4x. Basically, anytime a tree node is expanded the following HTTPService gets invoked:

            <mx:HTTPService id="getChildrenTypesRPC"
            resultFormat="e4x" showBusyCursor="true" method="post"
            <mx:XMLListCollection id="childrenTypes"
            source="{getChildrenTypesRPC.lastResult.type}" />

            The handler looks like this:

            private function getChildrenTypesRPCHandler(event:ResultEvent):void {

            for (var i:int = 0; i < childrenTypes.length; i++) {
            var newNode:XML = <type/>;
            var child:Object = childrenTypes.getItemAt(i);
            newNode.@name = child.@name;
            newNode.@type = child.@type;
            newNode.@annotation = child.@annotation;
            newNode.@isBranch = child.@isBranch;
            newNode.@namespaceURI = child.@namespaceURI;
            newNode.@isAttribute = child.@isAttribute;
            newNode.@isAbstract = child.@isAbstract;
            newNode.@isAttributeGroup = child.@isAttributeGroup;
            newNode.@isElement = child.@isElement;
            newNode.@isModelGroup = child.@isModelGroup;
            newNode.@isSimpleType = child.@isSimpleType;


            and the Tree is:

            <mx:Tree id="tree" top="124" bottom="10" right="10" left="10"
            itemRenderer="NIEMTreeItemRenderer" iconFunction="treeIconFunc"

            • 3. Re: How to force repaint/render of mx:Tree
              ntsiii Level 3
              All that looks right. And my example uses almost the exact same code and it works. If you debug and look at the xml node itself, does it have the correct content?

              Below is the code I use.
              //run by toolbar button, adds the type of node specified by sNodeKind
              private function addNode(sNodeKind:String):void
              var nodeParent:XML;
              var nodeNew:XML = <newnode />;
              switch (sNodeKind) {
              case "text": //NOT CURRENTLY USED
              var XMLdoc:XML = new XML();
              nodeNew = XMLdoc.appendChild("new text node");
              nodeParent = XML(_xmlNodeCurrent);
              case "sibling": //add a sibling node
              nodeParent = XML(_xmlNodeCurrent.parent()); //parent node of new node is this nodes parent
              case "child": //ad a child node
              nodeParent = XML(_xmlNodeCurrent); //parent node of new node is this node
              nodeParent.appendChild(nodeNew); //append the new node
              treeData.expandItem(nodeParent, true);
              treeData.selectedItem = nodeNew; //select the new node
              showNodeDetail(); //show the detail
              • 4. Re: How to force repaint/render of mx:Tree
                danFromBAH Level 1

                The XML document that gets generated after appending a child is not well formatted. For example if the initial XMLListCollection looks like:


                and I want to add a child to <one/>, the resulting xml looks like:


                It should look like:


                Any suggestions on how I could rework this.

                • 5. Re: How to force repaint/render of mx:Tree
                  danFromBAH Level 1
                  Disregard my last post. I got the XML to be formatted correctly. I check the structure of the XML after adding a child node and it is correct.

                  However, the tree is still not displaying the XMLListCollection correctly when I open the nodes near the bottom of the tree. No issues in the top portions of the tree.

                  For example if I add three children nodes to the last node of the tree below:


                  it should result in:


                  Instead I get,


                  The tree nodes disappear until I move the vertical scroll bar up and down!!
                  • 6. Re: How to force repaint/render of mx:Tree
                    ntsiii Level 3
                    Uh, that is bizarre. Maybe you should report a bug.

                    But first try the latest version 2.0.1, that was released today:

                    Also, try re-assigning the dataProvider. See if that does work.

                    • 7. Re: How to force repaint/render of mx:Tree
                      danFromBAH Level 1
                      I don't have a support plan. Can I still submit a bug report? where and how could i do that?
                      • 8. Re: How to force repaint/render of mx:Tree
                        I'm having the same issue. Except it only refreshes when I close/reopen (thats when it finishes rendering correctly).
                        • 9. Re: How to force repaint/render of mx:Tree
                          danFromBAH Level 1
                          When you say "... close/reopen ...", do you mean minimizing and maximizing the application window?
                          • 10. Re: How to force repaint/render of mx:Tree
                            rkschulz Level 1
                            Some problem here when adding or removing nodes from a model.
                            Everthing is fine when after scrolling tree up or down and / or expanding node.
                            Basically anything that forces a redraw.

                            Trying a few things at the moment to work around this problem but no luck - this seem like a bug in the tree renderer - I can't find a "model change" event or something one could fire to force the tree to redraw ...

                            • 11. Re: How to force repaint/render of mx:Tree
                              danFromBAH Level 1
                              I agree I believe it's a bug in the tree component. I have tried everything and nothing seems to work short of populating the tree dataProvider with all the nodes at tree creation time.