Hi,
The following example explain about the swapping two nodes based on the node index value.The newly updated the swap xml is maintained in the main XML. The swap XML was considered as a new xml then only it should be swap properly in XML otherwise it cannot perfefectly swap and reflect the changes to the XML.
<?xml version="1.0" encoding="utf-8"?>
<mx:application mx="http://www.adobe.com/2006/mxml" layout="absolute" creationcomplete="onInit()">
<mx:script>
<![CDATA[
private var _initXML:XML;
private var _xmlList:XMLList;
private function onInit():void
{
_initXML = XML(" ");
_xmlList = XMLList(_initXML.Fruits.fruit);
txt_area.text = _initXML.toXMLString();
}
private function onButtonClick():void
{
txt_area.text = swapXML(int(txt_old.text),int(txt_new.text));
}
private function swapXML(ind1:int,ind2:int):XML
{
var xml1:XML = new XML(_xmlList[ind1]);
var xml2:XML = new XML(_xmlList[ind2]);
_xmlList[ind1] = xml2;
_xmlList[ind2] = xml1;
return _initXML;
}
]]>
</mx:Script>
<mx:vbox paddingtop="10" paddingleft="10">
<mx:textarea id="txt_area" width="450" height="300">
<mx:hbox>
<mx:text text="Old Depth:" width="100">
<mx:textinput id="txt_old" width="100">
</mx:HBox>
<mx:hbox>
<mx:text text="New Depth:" width="100">
<mx:textinput id="txt_new" width="100">
</mx:HBox>
<mx:hbox paddingleft="30">
<mx:button label="Change" click="onButtonClick()">
</mx:HBox>
</mx:VBox>
</mx:Application>
The following example explain about the swapping two nodes based on the node index value.The newly updated the swap xml is maintained in the main XML. The swap XML was considered as a new xml then only it should be swap properly in XML otherwise it cannot perfefectly swap and reflect the changes to the XML.
<?xml version="1.0" encoding="utf-8"?>
<mx:application mx="http://www.adobe.com/2006/mxml" layout="absolute" creationcomplete="onInit()">
<mx:script>
<![CDATA[
private var _initXML:XML;
private var _xmlList:XMLList;
private function onInit():void
{
_initXML = XML("
_xmlList = XMLList(_initXML.Fruits.fruit);
txt_area.text = _initXML.toXMLString();
}
private function onButtonClick():void
{
txt_area.text = swapXML(int(txt_old.text),int(txt_new.text));
}
private function swapXML(ind1:int,ind2:int):XML
{
var xml1:XML = new XML(_xmlList[ind1]);
var xml2:XML = new XML(_xmlList[ind2]);
_xmlList[ind1] = xml2;
_xmlList[ind2] = xml1;
return _initXML;
}
]]>
</mx:Script>
<mx:vbox paddingtop="10" paddingleft="10">
<mx:textarea id="txt_area" width="450" height="300">
<mx:hbox>
<mx:text text="Old Depth:" width="100">
<mx:textinput id="txt_old" width="100">
</mx:HBox>
<mx:hbox>
<mx:text text="New Depth:" width="100">
<mx:textinput id="txt_new" width="100">
</mx:HBox>
<mx:hbox paddingleft="30">
<mx:button label="Change" click="onButtonClick()">
</mx:HBox>
</mx:VBox>
</mx:Application>
No comments:
Post a Comment