WEB开发网
开发学院图形图像Flash Understanding AS3 and XML 阅读

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 whi

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);
    }
   }
  }
 }
}

上一页  1 2 3 4 5 6 7 8  下一页

Tags:Understanding AS and

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接