I seem to recall trying to use setChildren to delete all of the child nodes of a node, but never made it work. Now, when I need to do that I loop over the children.
/** */ private function deleteChildren(xmlNode:XML):void { var xlChildren:XMLList = xmlNode.children(); for (var i:int=xlChildren.length()-1;i>=0;i--) { delete xlChildren[i]; //so remove all the children } }//deleteChildren Tracy ________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Tracy Spratt Sent: Thursday, November 27, 2008 12:35 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Re: Crash of safari, firefox using XML.setChildren for XML in a XMLListCollection First, if you are using a tree, why have you chosen XMLListCollection instead of XML. For hierarchical data, XML is easier to work with than nested collections. Next, you say, "XML doesn't send notifications". Why do you say that? And exactly what do you mean? XML is bindable. If you are using XML, then you delete a node using the "delete" operator and an e4x expresaion: delete myXML.myNode.(myexpression)[0]; NOTE: You cannot use a variable containing a reference to the node you want to delete, you must use the expression directly The concept of an "index" seems inherently linear. I don't know how one would implement it in a hierarchy. I have never been tempted to try to use it. Tracy ________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of shauncutts Sent: Thursday, November 27, 2008 11:44 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Crash of safari, firefox using XML.setChildren for XML in a XMLListCollection Thanks... I'll file one. But... why is it failing? In my mind, this should delete the node <b/> from <a> <b/> </a>. Of course, I haven't notified the Collection that I've modified the XML yet, and XML doesn't send notifications, so I'd have to put that in manually to get the display to change.... But why should this fail? In general, if I have a node of the a tree selected and pointed to by selectedChild, how should I go about deleting it? XMLListCollection.removeNodeAt doesn't seem to deal with it (I guess it works on the underlying list elements). Related to this, the selectedIndex isn't useful for addressing a subbranch. It seems to me that the specialization of ListCollectionView to XMLListCollection hasn't been thought through completely. I'd be grateful for suggested work-arounds for editing trees. --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "valdhor" <[EMAIL PROTECTED]> wrote: > > File a bug. > > I can see why it is failing but it should not crash the browser. > > > --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "shauncutts" <shaun@> wrote: > > > > The following code will crash Flash 9.0 r124 (debug version) when > > built with flex builder 3.0: (flash running on either Firefox or > > Safari, MacOS) > > > > <?xml version="1.0" encoding="utf-8"?> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> " > > layout="vertical" > > creationComplete="dotest();"> > > > > <mx:XMLListCollection id="tree_collection"> > > <mx:XMLList xmlns=""> > > <a> > > <b/> > > </a> > > </mx:XMLList> > > </mx:XMLListCollection> > > <mx:Script> > > <![CDATA[ > > public function dotest(): void > > { > > var data:XML = tree_collection[ 0 ]; > > data.setChildren( new XMLList() ); > > } > > > > ]]> > > </mx:Script> > > </mx:Application> > > >