How to convert ActionScript 2.0 code to ActionScript 3.0
this is code :
//***********************************************************
var theXML:XML = new XML();
theXML.ignoreWhite = true;
theXML.onLoad = function() {
var nodes = this.firstChild.childNodes;
for (i=0;i<nodes.length;i++){
theList.addItem(nodes[i].firstChild.nodeValue,i);
}
}
theXML.load("http://localhost/conn.php");
//***********************************************************
This is my PHP code that echo's an XML string :
echo "<?xml version=\"1.0\"?>\n";
echo "<name>\n";
while ( $line = mysql_fetch_assoc($res) )
{ echo "<item>" . $line["name"] . "</item>\n"; }
echo "</name>\n"
Using AS3, how do I parse the XML string as actual XML data with nodes?
There are many examples of how to work with XML in AS3, and how to migrate AS2 to AS3.
This would be the equivalent of what you posted:
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("http://localhost/conn.php"));
loader.addEventListener(Event.COMPLETE, loaderComplete);
function loaderComplete(e:Event):void {
XML.ignoreWhitespace = true;
var xml:XML = new XML(loader.data);
var nodes:XMLList = xml.child(0).children();
for (var i:int = 0; i < nodes.length(); i++) {
theList.addItem(nodes[i].child(0).text());
}
}
Note that in AS3 you can reference XML nodes by name, for example xml.gallery.image[3].url
instead of xml.child(0).children()[3].child(0)
, etc.