Frage

I am trying to convert an XMLList into an array of strings in as3 code. Here is the XMLList (lines):

<data>
   <conversation id="1" name="blah" key="area1" emptyState="false" background="null" alpha=".1">
    <scene numOfLines = "3">
      <lines>
          <line>This is a test for area1</line>
          <line>Hodor!</line>
          <line>The man who passes the sentence should swing the sword</line>
      </lines>
      <ll>bear</ll>
      <lr>shalev</lr>
      <rl>sarah</rl>
      <rr>taryn</rr>
    </scene>
  </conversation>
</data>

And here is the as3 code I use to convert it:

for each (var line:String in data.lines.line){
            conversationLine.push(line);
}

However the output isnt the text that appears in the xml (e.g. This is a test for area1) it is just the number of the line. So for the above code it would print 0, 1, 2.

Can anyone help me with this?

Thanks

War es hilfreich?

Lösung

The elements you are iterating over are XML objects, so you should cast your iterator to XML.

Example:

for each (var line:XML in data.lines.line){
    conversationLine.push(line.text());
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top