Understanding AS3 and XML
2009-10-26 00:00:00 来源:WEB开发网Now it’s time to scan each element and see if it has children. The children method lists the children of the XML object in the sequence in which they appear. So, now for each element I am scanning for children, and for each child (if any), for children of that child, and so on.
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.net.URLLoader;
public class sokoxml extends Sprite {
public function sokoxml() {
var loader:URLLoader=new URLLoader ;
var req:URLRequest=new URLRequest("sokobanxml.xml");
loader.addEventListener(Event.COMPLETE,on_xml_completed);
loader.load(req);
}
public function on_xml_completed(event:Event):void {
var xml_to_parse:XML=new XML(event.target.data);
for each (var item:XML in xml_to_parse.elements()) {
recursive(item);
}
}
public function recursive(xml:XML) {
trace("NAME: "+xml.name());
if (xml.children()==xml) {
trace("VALUE: "+xml.children());
trace("-----------------");
} else {
trace("This node has children:");
for each (var item:XML in xml.children()) {
recursive(item);
}
}
}
}
}
Tags:Understanding AS and
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接