XML Text

I call a Typewriter class that, when passed the text of a TextField, renders it letter-by-letter on the stage.

When, in my .fla file, I define the text to pass to Typewriter as:


var t1:TextField = new TextField();
t1.text = "Here is some text to type on the stage.";
var type:Typewriter = new Typewriter(t1.text); // more args but you get the point

…t1.text types nicely on the stage.

But… Now I want to put the text in an XML file and get it from there, rather than defining it brute-force in my .fla file. So here’s content.xml:


<CONTENT>
 <PAR1>
      Here is some text to type on the stage.
 </PAR1>
</CONTENT>

So in my .fla file, I’m attempting to get to the text in the XML file thus:


var xmlURL:URLRequest = new URLRequest("text/content.xml");
var xmlLoader:URLLoader = new URLLoader(xmlURL);
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
var dataXML:XML = new XML();
var t1:TextField = new TextField();
function xmlLoaded(e:Event) {
   dataXML = XML(e.target.data);
   t1.text = dataXML.PAR1.toString();
   trace("t1 = " + t1.text);
}
var type:Typewriter = new Typewriter(t1.text); 

But this doesn’t work, meaning the text doesn’t render Typewriter-style on the stage, even though the trace displays the text. What am I doing wrong?

One fact that is a hint but that I don’t understand is this: If I move the trace statement OUTSIDE my xmlLoaded function, it displays nothing. This is confusing to me because I instantiated t1 outside xmlLoaded. But I assume this has something to do with why apparently nothing is getting passed to Typewriter.

Thanks!