0

I have an xml file that has 3075 entries that look something like this

<item id="1" itype="COLOUR"></item>

I'm using action script 2 to load the xml and then a while loop the enter all data into an array using this code.

my_xml = new XML();
paper_crumbs = Array();
my_xml.load("sample.xml");
my_xml.onLoad = my_function;
my_xml.ignoreWhite = 1;

function my_function() {
var b = true;
var num = "1";
while(b == true){
paper_crumbs[my_xml.firstChild.childNodes[num].attributes.id] = {type: my_xml.firstChild.childNodes[num].attributes.itype, cost: 0, is_member: false}; 
if(my_xml.firstChild.childNodes[num].attributes.final == "yes"){
b = false;
trace("done");
}
num = num + 1;
}
}

The problem i am having is that it makes flash unresponsive then asks if i would like to terminate the script, is there any other way i can loop through the xml and add them to an array or could someone edit the while so it works?

1
  • I know it's been a while, but wanted top know if my answer resolved your issue. Just curious, thanks. :) Commented Dec 6, 2013 at 2:35

1 Answer 1

1

Some of syntax of your code is incorrect and I updated your XML format to make it easier to process and put it into an easier format to tweak later. I've created a sample shown below with code that properly loops over each entry in my sample.xml file.

sample.xml:

<items>
    <item id="1" itype="COLOUR"></item>
    <item id="2" itype="COLOUR"></item>
    <item id="3" itype="COLOUR"></item>
    <item id="4" itype="COLOUR"></item>
    <item id="5" itype="COLOUR"></item>
    <item id="6" itype="COLOUR"></item>
    <item id="7" itype="COLOUR"></item>
    <item id="8" itype="COLOUR"></item>
    <item id="9" itype="COLOUR"></item>
    <item id="10" itype="COLOUR"></item>
    <item id="11" itype="COLOUR"></item>
    <item id="12" itype="COLOUR"></item>
    <item id="13" itype="COLOUR"></item>
    <item id="14" itype="COLOUR"></item>
    <item id="15" itype="COLOUR"></item>
    <item id="16" itype="COLOUR"></item>
    <item id="17" itype="COLOUR"></item>
    <item id="18" itype="COLOUR"></item>
    <item id="19" itype="COLOUR"></item>
    <item id="20" itype="COLOUR"></item>
</items>

ActionScript:

my_xml = new XML();
paper_crumbs = Array();
my_xml.load("sample.xml");
my_xml.onLoad = my_function;
my_xml.ignoreWhite = true;

function my_function() {

    var rootNode:XMLNode = my_xml.firstChild;   // <items> node
    var itemNode:XMLNode = rootNode.firstChild; // get first child from <items>
    var xmlNodeID:Number;
    var xmlNodeType:String;

    while(itemNode != null){

        xmlNodeID = itemNode.attributes.id;
        xmlNodeType = itemNode.attributes.itype;

        paper_crumbs.push( {id: xmlNodeType, type: xmlNodeType, cost: 0, is_member: false} );

        itemNode = itemNode.nextSibling;

    } // end while

} // end function
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.