Can not read xml data into flash -


I write a simple XML code, and I try to read the XML file in Flash, but I'm "undefined" Production. The codes are the following: Do you know how to boil the problem? Thank you.

XML file (test.xml):

  & lt ;? XML version = '1.0' encoding = 'ISO-885 9-1'? & Gt; & Lt; Comment & gt; & Lt; Gt; & gt; Tom & lt; / Gt; & Lt; To & gt; Peter & lt; /> & Lt; Title & gt; Reminder & lt; / Heading & gt; & Lt; Body & gt; Do not forget me at the end of this week! & Lt; / Body & gt; & Lt; / Comment & gt;  

Flash program:

  xmlDoc = loadXMLDoc ("test.xml"); X = xmlDoc.getElementsByTagName ("for") [0]; T1.text = x.childNodes [0] .nodeValue;  

Honestly, John

Are you sure your Content XML file just this one line?

  Tom Peter's reminder does not forget me this weekend! If yes, then this may fix your problem or if your tags are missing in the question, then the reason is that you have to format the stack overflow to form it as code and code Need to format by pressing the button (or  Ctrl + K ). Please edit your question, otherwise I can not tell if there is a problem in the statement used to parse XML. 

Another problem I see that your script is in the script:
You can not load the XML file and can parse it immediately after it, because It does not happen sequentially (occurs in a separate thread). You need to use the URLLoader to load the XML, and the event of the URLLoader . Add an Event Listener to the Complementary
Event. In that method, what you have to do to parse XML.


I assume that you are using AS3 and not AS2

edit: added code sample

main method In where you start loading with XML

  var xmlLoader: URLLoader = new URLLoader (); XmlLoader.addEventListener (event .complete, show note);  

create a new method

  function show note (e: event): zero {var note: XML = new XML (e.target.data) ; Var to: string = note.to [0] .text (); From Var: String = Note. Frame [0] .text (); Var body: string = note.bb [0] .text (); //t1.text = "to:" + to + "\ nFrom:" + "\ n \ n" + body; T1.htmlText = "& lt; p & gt; To:" + to + "& lt; / p & gt; & lt; p & gt; From: +" + + + "+ & lt; / p & gt; & Lt; p & gt; From: + Body + "& lt; / P & gt; ";}  

Be sure to ensure that you have declared a text field on the stage with the example of t1 , and your properties To paint this work, wrap it.

So basically, I think the problem in your original code was one of the following:

  1. You Wanted a string, and to get it from XML node, you need to use the text () method as well as un Other methods are also, but it is fundamental.
  2. The way you are crossing the XML tree using getElementsByTagName and childNodes Correct, but it is definitely easy to do wrong AS3 provides a more intuitive tool for XML stuff like get , as I have given in my example.

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -