Flash parsing XML without loading an external file (as2)

In my flash, the socket server returns some xml data that I need to parse, but it seems that the only way to start the XML object is with the XML.Load() which loads an external file, but my XML file is already loaded into a variable

trace("raw: "+msg); msgArea.htmlText += "
update remote player loc"; var playerLocXMLOb = new XML(msg); playerLocXMLOb.ignoreWhite = true;

trace(playerLocXMLOb.firstChild.firstChild.nodeValue);

Which just returns

raw: <ploc><x>348</x><y>468</y><uid>red</uid></ploc>
null

Do you know what I am doing wrong? Or is an external file the only way?


No you're doing it correctly, I would try

trace(playerLocXMLOb.x);

AS has some very strange things with XML and you can actually access a node by treating it as a member variable. Give that a shot and see what happens.


不知道发生了什么问题,但这是我曾经解决的问题:

docXML = new XML(msg);
    XMLDrop = docXML.childNodes;
    XMLSubDrop = XMLDrop[0].childNodes;
    _root.rem_x = (parseInt(XMLSubDrop[0].firstChild));
    _root.rem_y = (parseInt(XMLSubDrop[1].firstChild));
    _root.rem_name = (XMLSubDrop[2].firstChild);

firstChild.nodeValue怎么firstChild.nodeValue

trace(playerLocXMLOb.firstChild.nodeValue);//should trace 438
链接地址: http://www.djcxy.com/p/17792.html

上一篇: 从Flash CS3到CS4迁移项目后的组件问题

下一篇: Flash解析XML而不加载外部文件(as2)