I'm having a slight problem getting XML data to read out in dynamic text files.
I'm doing a pretty small experiment here. The XML file loads fine. I just must
be making some small error in how I assign the value of the text fields to the
values in the XML file. Can anyone please tell me my error? I am using Flash
CS3 and ActionScript 3.
I have a simple XML file:
<?xml version="1.0" encoding="utf-8"?>
<primary>
<state>Montana</state>
<race_type>primary</race_type>
</primary>
In my .fla, I have a dynamic text field with an instance name of State_name. I
have another dynamic text field with an instance name of Type_race.
Then, in my .fla, I have this code:
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, onLoadXML);
loader.load(new URLRequest("dems.xml"));
function onLoadXML(ev:Event) {
try {
var myXML:XML = new XML(ev.target.data);
var list:XMLList = myXML.primary;
State_name.text = list.state;
Type_race.text = list.race_type;
}
catch (e:TypeError) {
trace("Could not parse the XML");
trace(e.message);
}
}
stop();
The Feldkircher - 13 May 2008 09:42 GMT
Hi
Have you tried to trace(list.state) and trace(list.race_type) if they return
undefined then your variable references are wrong.
If this is OK and you get correct node data, then try embeding a font on your
dynamic textboxes.
You never know, strange things can happen.
Hope it helps
Laura MS - 13 May 2008 16:25 GMT
Hi,
I dispensed with the list altogether and just used the XML object:
var myXML:XML = new XML(ev.target.data);
Then I refer to nodes in the XML like this:
myXML.statename[i]
I'll keep working on this so that I can iterate through the nodes in my XML
file without having to state them by name, but this syntax is working. Thanks!