日期:2014-05-18  浏览次数:20440 次

flash读取xml
function   praseXML   ()
{
for   (var   i   =   0;   i   <   myXML.firstChild.childNodes.length;   i   ++)
{
var   tempObj   =   myXML.firstChild.childNodes[i].attributes;
myArray.push   (
{
linkURL   :   tempObj.linkURL,
imgURL   :   tempObj.imgURL
})
}
ImageMax   =   myXML.firstChild.childNodes.length;
onHidden();
}

xml文件如下
<?xml   version= "1.0 "   standalone= "yes "?>
<ds>
    <Table>
        <linkURL> www.gofordesign.com </linkURL>
        <imgURL> 01.jpg </imgURL>
    </Table>
    <Table>
        <linkURL> www.gofordesign.com </linkURL>
        <imgURL> u=3779555069,3378449312&amp;gp=30.jp </imgURL>
    </Table>
    <Table>
        <linkURL> www.gofordesign.com </linkURL>
        <imgURL> 02.jpg </imgURL>
    </Table>
    <Table>
        <linkURL> www.gofordesign.com </linkURL>
        <imgURL> 02.jpg </imgURL>
    </Table>
    <Table>
        <linkURL> www.gofordesign.com </linkURL>
        <imgURL> 02.jpg </imgURL>
    </Table>
</ds>

没有读到linkURL   和imgURl,

------解决方案--------------------
这是我写的,LZ参考下
//数组,存放从xml中读取的数据
var arraystr:Array=new Array();

//读取xml从中获取图片标题以及图片地址,以及链接地址
var xmldoc:XML=new XML()
xmldoc.ignoreWhite = true;
xmldoc.onLoad=function(sucess)
{
if(sucess)
{
for(var i=0;i <xmldoc.firstChild.childNodes.length;i++)
{
var arrtmp:Array=new Array();
arrtmp.push(xmldoc.firstChild.childNodes[i].attributes[ "title "]);
arrtmp.push(xmldoc.firstChild.childNodes[i].attributes[ "imgpath "]);
arrtmp.push(xmldoc.firstChild.childNodes[i].attributes[ "link "]);
arraystr.push(arrtmp);
}
gotoAndPlay(2);
}
}
xmldoc.load( "flash/flashad.xml ");

这是名为flashad.xml的文件
<?xml version= "1.0 " encoding= "utf-8 "?>
<root>
<item title= "第一个 " imgpath= "1.jpg " link= "http://baidu.com/1 " />
<item title= "第二个 " imgpath= "3.jpg " link= "http://baidu.com/2 " />
<item title= "第三个 " imgpath= "6.jpg " link= "http://baidu.com/3 " />
<item title= "第四个 " imgpath= "7.jpg " link= "http://baidu.com/4 " />
<item title= "第五个 " imgpath= "9.jpg " link= "http://baidu.com/5 " />
</root>

我估计楼主是没有忽略空白元素,
xmldoc.ignoreWhite = true;
加上看看
------解决方案--------------------