Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-14-2012, 02:02 AM   #1
Claunchster
Registered User
 
Join Date: May 2012
Posts: 5
Unhappy Pulling Specific Data from XML

I need to be able to use as2 to search through my XML file and populate dynamic text field with certain data. Here's and example of my xml:

//-------------------- AS2 --------------------
function loadXML(loaded) {

if (loaded && typerank == "1"){

_root.firstperiod = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
_root.typerank= this.firstChild.childNodes[0].childNodes[6].firstChild.nodeValue;

ffscore1_1_txt.text=_root.typingtest;
ffname1_1_txt.text = _root.firstperiod;
}else {
trace("file not loaded!");
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("firstperiod.xml");
//-------------------- End AS2 --------------------

When I use this my xml doesn't load.

My xml actually looks like this:

//-------------------- XML --------------------
<fp>
<name>Last, First</name>
<abyss>736</abyss>
<abyssrank>6</abyssrank>
<adventure>35498</adventure>
<adventurerank>12</adventurerank>
<typingtest>19</typingtest>
<typerank>12</typerank>
<abysslw>736</abysslw>
<adventurelw>35498</adventurelw>
<typingtestlw>19</typingtestlw>
</fp>
//-------------------- End XML --------------------

I'm already using this xml to extrapolate data out of in other areas of the site and it works great. Now I just want to use it more in a different location to look at the "*rank" labels and see if they == 1, 2 or 3 and then fill in dynamic fields with the name, and score data. So I want to search for the highest grade and fill in a dynamic text field, or maybe the second highest grade and pull that data, and the name of the person. How could I do this?

Thanks!
Claunchster is offline   Reply With Quote
Old 05-14-2012, 09:29 AM   #2
arkitx
Senior Member
 
Join Date: Jan 2011
Posts: 703
Default

Instead of this:

if (loaded && typerank == "1"){}

write this:

if (loaded){}

This will help you to load the xml into your FLA.



__________________
Regards

arkitx
arkitx is offline   Reply With Quote
Old 05-14-2012, 09:59 AM   #3
arkitx
Senior Member
 
Join Date: Jan 2011
Posts: 703
Default

ActionScript Code:
//-------------------- AS2 -------------------- var permission:Boolean = false; function loadXML(loaded) {     if (loaded) {         var firstNode = this.firstChild.childNodes;         for (var i = 0; i<firstNode.length; i++) {             if (firstNode[i].nodeName == "typerank") {                 if (Number(firstNode[i].firstChild.nodeValue)>1) {                     permission = true;                     showText(firstNode);                 }             }         }     } else {         trace("file not loaded!");     } } function showText(xml:XML) {     trace("Permission: "+permission);     var node = xml;     for (var i = 0; i<node.length; i++) {         if (xml[i].nodeName == "name") {             trace(xml[i].firstChild.nodeValue.split(",")[1]);         }         if (xml[i].nodeName == "typerank") {             trace(xml[i].firstChild.nodeValue);         }     } } xmlData = new XML(); xmlData.ignoreWhite = true; xmlData.onLoad = loadXML; xmlData.load("firstperiod.xml"); //-------------------- End AS2 --------------------



__________________
Regards

arkitx
arkitx is offline   Reply With Quote
Old 05-14-2012, 05:08 PM   #4
Claunchster
Registered User
 
Join Date: May 2012
Posts: 5
Question

Hey arkitx, thanks for the assist. Yeah I can load data all day long using:
if (loaded){}
no problems, it's pulling the data that's tweeking me.

When I use your code I'm a little confused as to where it populates my txtfields. I currently have this:

ActionScript Code:
function showText(xml:XML) {     trace("Permission: "+permission);     var node = xml;     for (var i = 0; i<node.length; i++) {         if (xml[i].nodeName == "name") {             trace(xml[i].firstChild.nodeValue.split(",")[1]);             ffname1_1_txt.text = xml[i].nodeName == "name";//this is where i would pull the name for "name"         }         if (xml[i].nodeName == "typerank") {             trace(xml[i].firstChild.nodeValue);             ffscore1_1_txt.text = xml[i].nodeName == "typerank";//this is where i would pull the score for "typerank"         }     } }

but my text fields are still empty. I know I must sound like a total newb, mostly because I am . . .

thanks!
Claunchster is offline   Reply With Quote
Old 05-14-2012, 07:16 PM   #5
arkitx
Senior Member
 
Join Date: Jan 2011
Posts: 703
Default

ActionScript Code:
if (xml[i].nodeName == "name") {             trace(xml[i].firstChild.nodeValue.split(",")[1]);             ffname1_1_txt.text =xml[i].firstChild.nodeValue.split(",")[1];         }         if (xml[i].nodeName == "typerank") {             trace(xml[i].firstChild.nodeValue);             ffscore1_1_txt.text = (xml[i].firstChild.nodeValue;         }


You just have to replace the trace to target that value into your TextField.




__________________
Regards

arkitx
arkitx is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:38 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.