I have this simple test code with your test data:
var s:String = "rangelow1=b&rangehigh1=bb&bed1=a&LoZip1=bb";
var u:URLVariables = new URLVariables(s);
trace(u.bed1, u.LoZip1, u.rangelow1, u.rangehigh1);
And none of them is appearing as null. So parsing seems okay, but the following logic is wrong:
if (books.indexOf(book) == books.length - 1) {
finish()
}
URLLoader
loads data asynchronously, so there is no guarantee that all books will be loaded in the same order as you requested. Based on the network connection the last book data might be loaded before the previous one's data. In that case you will get null value in finish
. To solve this instead of using indexof
use a counter variable to count how many books are loaded and call finish
once counter == books.length
.
var counter:int = 0;
private function response(book:BookVO):void {
counter++;
if (counter == books.length) {
finish();
}
}