dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Xml and array Problem Newbie please help

  1. #1
    Senior Member
    Join Date
    May 2005
    Location
    Wisconsin
    Posts
    181

    Xml and array Problem Newbie please help

    Im trying to parse this xml doc here is a link to the xml Doc
    Here is a link to the Source code .fla

    My traces are returning the correct information except when i try to call
    trace(ans[0, 0, 2]); which sould result in this answer " 'EXPENDABLE MOLD SINGLE USE PATTERN EXPENDABLE MOLD MULTIPLEľUSE PATTERN PERMANENT MOLD NO PATTERN"

    Im getting ans[4 4 2] "THESE REGIONS COOL MORE RAPIDLY DUE TO HIGHER RATIO OF SURFACE AREA TO VOLUME"

    The source code is below. Can you tell me what im doing wrong? I no there has to be an easier way to populate my array.
    Any help would be great this is my first attempt at parsing a xml doc and using an array.

    Code:
    function loadXML(loaded) {
    	if (loaded) {
    		xmlNode = this.firstChild;
    		//question
    		qst = [j, i, t];
    		//answer to question
    		ans = [j, i, t];
    		//Value of question
    		val = [j, i, t];
    		for (j=0; j<5; j++) {
    			//5 categories
    			for (i=0; i<5; i++) {//5 sets of different questions
    				for (t=0; t<1; t++) {
    					//One question
    					qst[j, i, t] = xmlNode.childNodes[j].childNodes[i].childNodes[t].firstChild.nodeValue;
    					trace(j+" "+i+" "+t+" qst[j][i][t]"+qst[j, i, t]);
    				}
    				for (m=1; m<2; m++) {//One value
    					val[j, i, m] = xmlNode.childNodes[j].childNodes[i].childNodes[m].firstChild.nodeValue;
    					trace(j+" "+i+" "+m+" val[j][i][m]"+val[j, i, m]);
    				}
    				for (n=2; n<3; n++) {//One answer
    					ans[j, i, n] = xmlNode.childNodes[j].childNodes[i].childNodes[n].firstChild.nodeValue;
    					trace(j+" "+i+" "+n+" ans[j][i][n]"+ans[j, i, n]);
    				}
    			}
    		}
    	} else {
    		content = "file not loaded!";
    	}
    	trace("end");
    	trace(ans[0, 0, 2]);
    	//Sould result to 'EXPENDABLE MOLD SINGLE USE PATTERN EXPENDABLE MOLD MULTIPLEľUSE PATTERN PERMANENT MOLD NO PATTERN'
    }
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("newgra2.xml");

  2. #2
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    Why are you using a 3 dimensional array to store your values. From what I can see you are not making anything easier for yourself with your array.

    Why not use a one dimensional array instead and just increment the index by one for each each question/answer that you get?

    Thanks

    Luke
    Flash-XML FAQ
    http://www.tupps.com/flash/faq/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center