0 Replies Latest reply on Dec 29, 2009 5:43 PM by Ban the Rewind

    appendChild() and delete bugs in Flash Builder Beta 2

    Ban the Rewind

      I found two bugs while working on a project today that both relate to manipulating XML on a parent clip or root.  Basically, if you try to use "appendChild" on item 1 (0 index), Flash Builder thinks that you are looking for a node, not running a function, and return a XMLList.  If you try to delete a node from the same spot, you get an error, as well.  However, other functions, like replace, work find

       

       

       

      var node_xml:XML = new XML("<myNode />");


      root["data_xml"].children()[0].appendChild(node_xml);   // Works

      root["data_xml"].children()[1].appendChild(node_xml);   // Doesn't work

      root["data_xml"].children()[2].appendChild(node_xml);   // Works


      root["data_xml"].item0[0].appendChild(node_xml);   // Works (Assume item0, item1, etc... indicates index)

      root["data_xml"].item1[1].appendChild(node_xml);   // Doesn't work

      root["data_xml"].item2[2].appendChild(node_xml);   // Works


      root["data_xml"].children()[1].replace(0, node_xml:XML);   // Works


      delete root["data_xml"].children()[0].myNode[0];   // Works

      delete root["data_xml"].children()[1].myNode[0];   // Doesn't work

      delete root["data_xml"].children()[2].myNode[0];   // Works

       

       

       

      One work around is to add a useless node in that position, but that could get messy.  So I did this instead:

       

      var node_xml:XML = new XML("<myNode />");


      // Convert the XML to a string and use it to create a new, local object

      var root_xml:XML = new XML(root["data_xml"].toXMLString());


      // Manipulating the local object works fine

      root_xml.children()[1].appendChild(node_xml);

      delete root_xml.children()[1].children()[0];


      // Overwrite the root or parent XML with a new XML

      // object made from the local object's string

      root["data_xml"] = new XML(root_xml.toXMLString());