
I’m loading an xml file that contains nothing more than a list of "valid" zip codes. Here’s a sample of the xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<zipCodes>
<zip>82930</zip>
<zip>82931</zip>
<zip>83114</zip>
<zip>83201</zip>
<zip>83202</zip>
<zip>83203</zip>
<zip>83204</zip>
<zip>83205</zip>
<zip>83206</zip>
<zip>83209</zip>
<zip>83210</zip>
<zip>83211</zip>
<zip>83212</zip>
<zip>83213</zip>
<zip>83214</zip>
<zip>83215</zip>
<zip>83217</zip>
…and so on.What I need to happen is when a user enters a zip code, I need to return a "yes" or "no" based on whether or not the zip code they entered is in the xml list. So far, it only works if the zip they enter happens to be the last one on the list. This tells me that it’s either not searching the entire file, or that it perhaps needs to search in a loop somehow.
Here’s the code that works the closest to what I need:
stop();
var xmlLoader:URLLoader = new URLLoader;
xmlLoader.addEventListener(Event.COMPLETE, showXML);
xmlLoader.load(new URLRequest("zipCodes.xml"));
var xmlData:XML;
function showXML(e:Event):void {
xmlData = new XML(e.target.data);
var i:Number;
for each (var child:XML in xmlData.*){
trace(child);
var thisHere = textfield.text;
if (thisHere == child){
textfieldDisplay.text = "this worked";
}else{
textfieldDisplay.text = "nope";
}
}
}
I know this is probably waaaaaay wrong, so I’m asking for help. Thanks in advance!
If you would like to make a comment, please fill out the form below.
Recent Comments