Skip to main content
Inspiring
August 2, 2013
Answered

Displaying dynamic text from an xml file

  • August 2, 2013
  • 1 reply
  • 862 views

I am attempting to display dynamic text from an external xml file. When I trace for the variable, all is well in the output window. But the text does not display in the published movie.

Here is my current code:

var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("AskAnExpert.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
myXML = new XML(e.target.data);

var topic1:String = myXML.TOPIC[0].TOPIC_NAME;

trace(topic1)

};

On-screen, I have a dynamic text field with an instance name of topic1. When I play the movie, the text does not display. I've tried various options of embedding the text and using _sans, but that doesn't seem to do the trick either. Help!

This topic has been closed for replies.
Correct answer Ned Murphy

You say you have a textfield with an instance name of topic1, but in your code you also declare a variable topic1 that you cast as a String.  The two cannot coexist.  If you really do have a textfield named topic1then assign the xml value to the textfield using...

topic1.text = myXML.TOPIC[0].TOPIC_NAME;

But do not use a varioable with the same name as the textfield

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
August 2, 2013

You say you have a textfield with an instance name of topic1, but in your code you also declare a variable topic1 that you cast as a String.  The two cannot coexist.  If you really do have a textfield named topic1then assign the xml value to the textfield using...

topic1.text = myXML.TOPIC[0].TOPIC_NAME;

But do not use a varioable with the same name as the textfield

Inspiring
August 3, 2013

Thank you!

Ned Murphy
Legend
August 3, 2013

You're welcome