flash as代码解释 读取XML 另存问xml?高分

functionXmlToData(xmlData){var_loc6=xmlData.childNodes[0].childNodes.length;var_loc3=... function XmlToData(xmlData)
{
var _loc6 = xmlData.childNodes[0].childNodes.length;
var _loc3 = xmlData.childNodes[0].childNodes;
for (var _loc1 = 0; _loc1 < _loc6; ++_loc1)
{
if (_loc3[_loc1].nodeName == "flv")
{
Flv_url = _loc3[_loc1].attributes.url;
continue;
} // end if

} // end of for
Root.mc.gotoAndPlay(2);
} // End of the function
Stage.align = "CT";
Stage.scaleMode = "noScale";
var Root = _root;
var pType = System.capabilities.playerType;
if (pType == "StandAlone" || pType == "External")
{
xmlDoc = "xml/GSPteaser.xml";
}
else if (pType == "PlugIn" || pType == "ActiveX")
{
xmlDoc = _root.tPath + _root.fPath;
} // end else if
trace (xmlDoc);
var myXML = new XML();
myXML.onLoad = function (success)
{
var _loc2;
switch (this.status)
{
case 0:
{
_loc2 = "???? ??? ???????.";
break;
}
case -2:
{
_loc2 = "CDATA ?? ?????.";
break;
}
case -3:
{
_loc2 = "XML?? ?????.";
break;
}
case -4:
{
_loc2 = "DOCTYPE?? ?????.";
break;
}
case -5:
{
_loc2 = "?? ?????.";
break;
}
case -6:
{
_loc2 = "XML ?? ?????.";
break;
}
case -7:
{
_loc2 = "??? ???? ?? ?????.";
break;
}
case -8:
{
_loc2 = "?? ?? ?????.";
break;
}
case -9:
{
_loc2 = "?? ??? ? ?? ?? ?????.";
break;
}
case -10:
{
_loc2 = "? ??? ???? ?? ?? ?? ?????.";
break;
}
default:
{
_loc2 = "? ? ?? ?????.";
break;
}
} // End of switch
var _loc3 = this.status;
trace ("XML???? : [ errorCode " + _loc3 + " ] " + _loc2);
if (this.status == 0)
{
XmlToData(myXML);
}
else
{
trace ("XML???? : XML? ??/?? ? ? ????. ");
} // end else if
};
System.useCodepage = true;
myXML.load(xmlDoc);
myXML.ignoreWhite = true;
var Flv_url;
var Create_url;
var Create_type;
var img_url_array = new Array();
我要读取XML
<?xml version="1.0" encoding="UTF-8"?>

<GSPteaser>
<flv url="http://www.qqq.com/Teaser.flv" />
<create_account url="http://www.qq.com/step01.asp" type="_blank" />
<imgList>
<download url="javascript:imgWinOpen('http://www.qq.com/01.jpg','t','1280','700');"/>
<download url="javascript:imgWinOpen('http://www.qq.com/02.jpg','t','1280','700');"/>
...
</imgList>
</GSPteaser>
这个不用变量怎么写

if (_loc3[_loc1].nodeName == "flv")
{
Flv_url = _loc3[_loc1].attributes.url;
continue;
} // end if

============================================================
if (xmlData.childNodes[0].childNodes[0].nodeName == "flv")
{
Flv_url = xmlData.childNodes[0].childNodes[0].attributes.url;
continue;
} // end if

是读取第一层中间first... 小弟不没有学过,请大侠赐教
展开
 我来答
百度网友4935f44e5
2009-04-16 · TA获得超过1493个赞
知道大有可为答主
回答量:1905
采纳率:0%
帮助的人:1311万
展开全部
读取第一个是
flv = xmlData.firstChild.childNodes[0].attributes.url
读取第二个是
flv = xmlData.firstChild.childNodes[1].attributes.url
最后面的url是你在<flv url="......" />里取的变量.

//以下内容就是载入xml文件后解析里面的内容,这里是根据内容而设置的。
function XmlToData(xmlData) {
//大概意思是xml第一层开始的下一级的第一个的下一级的层级个数。
var _loc6 = xmlData.childNodes[0].childNodes.length;
//大概意思是xml第一层开始的下一级的第一个的下一级的层级。
var _loc3 = xmlData.childNodes[0].childNodes;
//以下你自己试着理解吧,最好你在网上看些教程,关于flash+xml的
for (var _loc1 = 0; _loc1<_loc6; ++_loc1) {
if (_loc3[_loc1].nodeName == "flv") {
Flv_url = _loc3[_loc1].attributes.url;
continue;
}
// end if
}
// end of for
Root.mc.gotoAndPlay(2);
}
//------------------------------------------
//Stage.是屏幕设置,一个是无缩放,一个是左上对齐(大概是)
Stage.align = "CT";
Stage.scaleMode = "noScale";
//------------以下不清楚你的变量设置!
var Root = _root;
var pType = System.capabilities.playerType;
if (pType == "StandAlone" || pType == "External") {
xmlDoc = "xml/GSPteaser.xml";
} else if (pType == "PlugIn" || pType == "ActiveX") {
xmlDoc = _root.tPath+_root.fPath;
}
// end else if
trace(xmlDoc);

//******首先你应该先从这里看启!!!

//载入XML文件执行语段。定义myXML
var myXML = new XML();
myXML.onLoad = function(success) {
//声明_loc2
var _loc2;
switch (this.status) {
//如果此场景的变量status等于0那么_loc2等于...
case 0 :
_loc2 = "???? ??? ???????.";
break;
//如果此场景的变量status等于-2那么...
case -2 :
_loc2 = "CDATA ?? ?????.";
break;
//......
case -3 :
_loc2 = "XML?? ?????.";
break;
case -4 :
_loc2 = "DOCTYPE?? ?????.";
break;
case -5 :
_loc2 = "?? ?????.";
break;
case -6 :
_loc2 = "XML ?? ?????.";
break;
case -7 :
_loc2 = "??? ???? ?? ?????.";
break;
case -8 :
_loc2 = "?? ?? ?????.";
break;
case -9 :
_loc2 = "?? ??? ? ?? ?? ?????.";
break;
case -10 :
_loc2 = "? ??? ???? ?? ?? ?? ?????.";
break;
default :
_loc2 = "? ? ?? ?????.";
break;
}
// End of switch
var _loc3 = this.status;
trace("XML???? : [ errorCode "+_loc3+" ] "+_loc2);
//如果此场景里的变量status 等于 0
if (this.status == 0) {
//那么开始执行函数XmlToData() 最上边!
XmlToData(myXML);
} else {
trace("XML???? : XML? ??/?? ? ? ????. ");
}
// end else if
};
//----------------载入xml必要代码。
System.useCodepage = true;
myXML.load(xmlDoc);
myXML.ignoreWhite = true;
//----------------
var Flv_url;
var Create_url;
var Create_type;
var img_url_array = new Array();
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式