Writing url to file

I’m looking to create a flash app that pulls it’s information from an rss feed. But in order to get the specified rss feed I need to plug in a varible that will specify the rss feed. And to throw in another monkey into the wrench, to start things off I would like to start the whole process by entering in a completely different value. So here an example:

There’s a text box that you enter your city or zipcode. (bejing, china) the code then plugs thoughs values into this url http://weather.yahoo.com/search/weather2?p=beijing%20china which then returns the url http://weather.yahoo.com/forecast/CHXX0008.html. Then what I need is the “CHXX0008” in order to plug it in to my rss feed wich would be http://xml.weather.yahoo.com/forecastrss?p=CHXX0008&u=f

I figure it would problably be easier to query yahoo’s database of city codes, but I can’t figure out how they’re even doing it, so I thought this might be a way around. Any help would be greatly appreciated.