Hello,
I have a problem with my video. On the Stage I have an input box (book_box) with a “submit” (submit_btn) button.
The purpose is to read an xml file for a phrase (the input box) and then output the phrase when found.
The problem is it only ever reads the 2nd item in the XML list… So In this case, test.
The XML
<root>
<books>
<book>
<title>Learning</title>
</book>
<book>
<title>test</title>
</book>
<book>
<title>ActionScript</title>
</book>
</books>
</root>
The AS3
stop();
//Define The Key word that is in the input box on load.
book_box.book_txt.text=“Book Title”;
//Setup the submit button as a button and its event listener
submit_btn.buttonMode=true;
submit_btn.addEventListener(MouseEvent.CLICK, submit);
//the buttons function handler
function submit(e:Event) {
//Loads the XML
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, onComplete);
xmlLoader.load(new URLRequest(“store.xml”));
function onComplete(evt:Event):void {
var xmlData:XML=new XML(evt.target.data);
var bookTitles:XMLList=xmlData.books.book;
// loop that scans the XML file
for (var n = 0; n<= xmlData.books.length(); n++) {
if (bookTitles[n].title==book_box.book_txt.text) {
trace(bookTitles[n].title);
} else {
trace("no Book");
}
}
}
}