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

Understanding AS3 and XML

 2009-10-26 00:00:00 来源:WEB开发网   
核心提示: The last thing I have to do is checking for attributes. An element can have one or more attributes, or can have no attributes. Also, I don’t k

The last thing I have to do is checking for attributes. An element can have one or more attributes, or can have no attributes. Also, I don’t know their names and values. That’s when attribute method comes and saves me. attribute returns a list of attribute values for the given XML object.

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());
   for each (var att:XML in xml.attributes()) {
    trace("Attribute: "+att.name()+" = "+att);
   }
   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);
    }
   }
  }
 }
}

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

Tags:Understanding AS and

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