XML has a copy method that might help here : 

from the docs :

Example 


This example shows that the copy() method creates a new instance of an XML 
object. When you modify the copy, the original remains unchanged:
var xml1:XML = <foo />;
var xml2:XML = xml1.copy();
xml2.appendChild(<bar />);
trace(xml1.bar.length()); // 0
trace(xml2.bar.length()); // 1


-----Original Message-----
From: [email protected] on behalf of Alex Harui
Sent: Wed 20/08/2008 21:52
To: [email protected]
Subject: RE: [flexcoders] Normalize removing my data??? Is this a bug in Flex?
 
Isn't it because the XMLList has references to the original nodes and
not copies?

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of flexaustin
Sent: Tuesday, August 19, 2008 11:02 PM
To: [email protected]
Subject: [flexcoders] Normalize removing my data??? Is this a bug in
Flex?

 

I have been tracing this bug for two days and finally found it. I
don't see how this .normalize method is changing data in other areas
of my code?

So when makeData is called I pass it xml with child nodes. It is
stored in _data and then I se several variables and call the the
buildXMLObj method. When inside the buildXMLObj when the line with
.normalize is run my variable _data (now only contains parent nodes
with out the children). The buildXMLObj removes children but it is
never assigned to _data so how is _data getting changed?

package 
{
public class DataDelegate
{
import mx.rpc.AsyncToken;
import mx.utils.ObjectUtil;

import com.models.ViewModelLocator;

private var modelLocator:ViewModelLocator =
ViewModelLocator.getInstance();
private var _newSelected:int = 0;
private var midXML:XMLList;
private var _data:XMLList;

public function DataDelegate(){

}

private function buildXMLObj(xmllist:XMLList):void
{
var copyOfList:XML = <groups/>;
for each (var xl:XML in xmllist)
{
if (xl.length())
{
xl.replace("*", "");
}
copyOfList.appendChild(xl);
}
copyOfList = copyOfList.normalize();
midXML = copyOfList.descendants("*");

}

public function makeData(datas:XML):void
{
trace("MakeData was called
---------------------------------------------------");
var _data:XML = datas;
modelLocator.selected = -1;
var xml:XML = datas as XML;
var _newSelected:int;

var comps:XMLList = xml.group.component;
buildXMLObj(xml.group);
var groups:XMLList = midXML;

if (modelLocator.comps.length() > 0)
{ 
_newSelected = parseInt([EMAIL PROTECTED]);
modelLocator.selected = _newSelected;
}
/* modelLocator.allDataArr.splice(_newSelected,1); */
modelLocator.allDataArr[_newSelected] = _data; 
modelLocator.comps = comps;
modelLocator.groups = groups;
}
}
}

 



______________________________________________________________________
This communication is from Primal Pictures Ltd., a company registered in 
England and Wales with registration No. 02622298 and registered office: 4th 
Floor, Tennyson House, 159-165 Great Portland Street, London, W1W 5PA, UK. VAT 
registration No. 648874577.

This e-mail is confidential and may be privileged. It may be read, copied and 
used only by the intended recipient. If you have received it in error, please 
contact the sender immediately by return e-mail or by telephoning +44(0)20 7637 
1010. Please then delete the e-mail and do not disclose its contents to any 
person.
This email has been scanned for Primal Pictures by the MessageLabs Email 
Security System.
______________________________________________________________________

<<winmail.dat>>

Reply via email to