an AS2 XML Glossary with text loading

HostMx Alon

New Member
I have the following glossary as2 XML code example from flashkit and when I was trying to do a trace to see how is the text being loaded from the XML, I couldn't get how the code actually finds the correct entry to load. When I do the trace, it returns me the full array of the XML entries instead of a single one. \[code\] _master.termByID = function(termID:String) { displayTermByID(termID);};function displayTermByID(termID:String):Void { var info:String = ""; var originalTerm = termID; var found = findTermIndex(termID); trace("im here"); while(found == -1 && termID.length > 0){ info = "The referenced term ID <i>"+originalTerm+"</i> was not found. <br>"; trace("info:"+info); found = findTermIndex(termID); trace("found:"+found); termID=termID.substr(0,termID.length-1); trace("termID:"+termID); } if(found != -1 && originalTerm != termID){ info += "Displaying closest matches: " + termID + "<br>"; } else if (termID.length ==0){ info += "No substring yielded any matches.<br>"; } whichTerm = found; updateInterface(info);}\[/code\]this is the main method used to display the text but when i did the trace, it does not even shows up in the console and yet the text is being displayed in the textbox.\[code\]function findTermIndex(termID:String):Number { var pow:Number = 2; var numTerms = termArray.length; var split:Number = Math.round(numTerms/pow); var currId = termArray[split].attributes.id; while (currId != termID && numTerms/pow>.5) { pow *= 2; if (currId<termID) { split += Math.round(numTerms/pow); } else { split -= Math.round(numTerms/pow); } currId = termArray[split].attributes.id; } if (currId == termID) { return (split); } else { return (-1); }}\[/code\]this is used to find the term index. \[code\]function parse(glosSrc:XML):Void { var numTerms = glosSrc.childNodes.length; for (var i = 0; i<numTerms; i++) { var thisChild = glosSrc.childNodes; var insertPoint = termArray.length; while (insertPoint>0 && termArray[insertPoint-1].attributes.id>thisChild.attributes.id) { insertPoint--; } termArray.splice(insertPoint, 0, thisChild); // use this to get the imgURL value //trace(glosSrc.childNodes.childNodes[1].firstChild.nodeValue); //thisImg = String(glosSrc.childNodes.childNodes[1].firstChild.nodeValue); } searchTerms(""); //imgLoader.contentPath = thisImg;}\[/code\]the XML parse function\[code\]function displaySearchResults(matches:Array):Void { var numMatches = matches.length; if (numMatches) { var resultString = '<textformat leading="'+resultLineSpacing+'"><font size="'+fontSize+'">'; for (var i = 0; i<numMatches; i++) { resultString += '<a href="http://stackoverflow.com/questions/11104990/asfunction:displayTermByIndex,'+matches+'">'; var fullTerm = termArray[matches].firstChild.firstChild.firstChild.nodeValue; var cleanTerm = escapeAtChar(fullTerm); resultString += cleanTerm+'</a><br>'; //trace(resultString); } resultString += '</font></textformat>'; //def.setTextFormat(resultFormatting); def.htmlText = resultString; //trace(resultString); } else { def.htmlText = '<font color="#'+errorHexColor+'" size="'+(fontSize+2)+'">No matching terms found.</font>'; } gBoxPath.onComplete();}\[/code\]another method used to display the resulting text from the XML. def is the dynamic textbox object being used to display the text. so with all these methods, I have traced all the possible Strings that is being passed but all seems to either not return anything or it returns a whole lot of parameters instead of the one that is supposed to be shown. would be glad if someone can explain how the code actually works so i add in more fields in the XML. the whole source file is available here.https://www.dropbox.com/s/34acpm66adk9f62/glossary%203.zip
 
Back
Top