Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Data Integration / May 2008



Tip: Looking for answers? Try searching our database.

Trouble getting XML data to display

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Laura MS - 12 May 2008 18:52 GMT
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!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.