4 Replies Latest reply on Jan 3, 2007 4:19 AM by farmazone

    Can not add a new node into the Tree!!!

    rambo_bb
      my codes:
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

      <mx:Script>
      <![CDATA[

      public function addAction():void
      {
      var xml:XML = <node label="New TEST"/>;
      treeData.insertChildAfter(myTree.selectedItem, xml);
      }
      ]]>
      </mx:Script>

      <mx:XMLList id="treeData">
      <node label="Mail Box">
      <node label="Inbox">
      <node label="Marketing"/>
      <node label="Product Management"/>
      <node label="Personal"/>
      </node>
      <node label="Outbox">
      <node label="Professional"/>
      <node label="Personal"/>
      </node>
      <node label="Spam"/>
      <node label="Sent"/>
      </node>
      </mx:XMLList>

      <mx:Panel title="Tree Control Example" height="75%" width="75%"
      paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
      <mx:Button label="Add a new Node" click="addAction();"/>
      <mx:Tree id="myTree" width="50%" height="100%" labelField="@label"
      showRoot="false" dataProvider="{treeData}"/>

      </mx:Panel>
      </mx:Application>

      Only "Mail Box" can be added into a new node, and not in the others, why?
        • 1. Re: Can not add a new node into the Tree!!!
          bnambooz
          the insertChildAfter() call is working correctly for me when I run your code if you select one of Mailbox's children. You can't do an insert when you select the Mailbox node because its the root node and you can only have one root node with e4x XML.
          • 2. Re: Can not add a new node into the Tree!!!
            rambo_bb Level 1
            Thanks a lot for your answer.

            Yes, it can do an insert when you select the node(parent == "Mail Box"), but a problem will be happened if you select the node(as "<node label="Marketing"/>", parent=="Inbox", not "Mail Box"), none will be inserted into the tree.

            let's do more test.

            var xml:XML = <node label="New TEST"/>;

            //Add a new node as the child of the "Mail Box", afther "Inbox"
            treeData.insertChildAfter(treeData.node[0], xml);//OK

            //Add a new node as the child of the "Inbox", after the node(<node label="Marketing"/>)
            treeData.insertChildAfter(treeData.node[0].node[0], xml);//Some problem here
            • 3. Re: Can not add a new node into the Tree!!!
              Level 7
              Thanks a lot for your answer.

              Yes, it can do an insert when you select the node(parent == "Mail Box"), but a
              problem will be happened if you select the node(as "<node label="Marketing"/>",
              parent=="Inbox", not "Mail Box"), none will be inserted into the tree.

              let's do more test.

              var xml:XML = <node label="New TEST"/>;

              //Add a new node as the child of the "Mail Box", afther "Inbox"
              treeData.insertChildAfter(treeData.node[0], xml);//OK

              //Add a new node as the child of the "Inbox", after the node(<node
              label="Marketing"/>)
              treeData.insertChildAfter(treeData.node[0].node[0], xml);//Some problem here


              • 4. Re: Can not add a new node into the Tree!!!
                farmazone
                from run time errors http://livedocs.macromedia.com/labs/as3preview/langref/runtimeErrors.html
                "1086 The _ method only works on lists containing one item.

                The XMLList class propagates the XML-specific functions to one child if it has only one item in its list. If more than one item is in the list, the routines fail with this error. This happens for the following XMLList functions that mimic XML functions:

                addNamespace, appendChild, childIndex, inScopeNamespaces, insertChildAfter, insertChildBefore, name, namespace, localName, namespaceDeclarations, nodeKind, prependChild, removeNamespace, replace, setChildren, setLocalName, setName, and setNamespace. "