[Flash x]简单读取xml文件

      Flash 2006-3-13 17:18
例如XML文件格式如下:
<mp3>
<item title='1' link='/mp3/1.mp3'></item>
<item title='2' link='/mp3/2.mp3'></item>
</mp3>

AS代码如下:
var mp3_xml:XML = new XML();
mp3_xml.onLoad = function(success) {
  if (success == true) {
    this.ignoreWhite = false;
    var t_data = this.firstChild.childNodes;
    for (var i = 0; i<t_data.length; i++) {
      if (t_data[i].attributes.link != undefined) {
        trace("NO."+(i+1)+" title="+t_data[i].attributes.title+" link="+t_data[i].attributes.link);
      }
    }
  } else {
    trace(success);
  }
};
mp3_xml.load("mp3.xml");

输出结果为:
NO.1 title=1 link=/mp3/1.mp3
NO.2 title=2 link=/mp3/2.mp3

注意:
XML文件路径
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}