Trouble with xml zip code lookup

By bradgrubbs | Jun 26, 2009

actionscript3

Hey guys! I’m as new to the forums as I am to AS3. Needless to say, I need a little help here.

I’m loading an xml file that contains nothing more than a list of "valid" zip codes. Here’s a sample of the xml:

Code:

<?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:

Code:

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!

actionscript3

Please reply at our Forum

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 ActionScript 3.0