Hello,
I am trying to create a weather app in Flex Builder 2 but I have an issue.
The XML comes in with hyphens in the names and as a string and AS3 didn’t like that.
I went through and converted all the hyphens to underscores, that worked I thought, but then when a negative value for a measurement comes in it is no longer a number. So know I am trying a RegExp to change all the hyphens followed by an alpha character to underscores. I am getting out of my league now being a measly interface designer and I want to see if anyone can help me clean up the code to get it to work. I had it working in Flash CS3 but Flex is a little more strict it seems. Here it is:
// resultHandler
private var wxDataString:String;
private function resultHandler(event:ResultEvent):void {
wxDataString = event.result as String;
wxDataString = findSearchReplace(wxDataString);
var wxData:XML = new XML(wxDataString);
lat = wxData..@latitude;
lon = wxData..@longitude;
trace(wxData..@period_name[0]);
//Display New Cords
myCord = "N" + lat + " W" + lon;
latInput.text = lat + "";
lonInput.text = lon + "";
dayBox1.nameOfDay.text = wxData..@period_name[0];
dayBox2.nameOfDay.text = wxData..@period_name[1];
dayBox3.nameOfDay.text = wxData..@period_name[2];
dayBox4.nameOfDay.text = wxData..@period_name[3];
dayBox5.nameOfDay.text = wxData..@period_name[4];
}
private var sNew:String = "";
private var i:Number = 0;
private var searchResult:Array = [0];
private function findSearchReplace(wxDataString:String):String {
for (i=0; searchResult!=null; i++) {
// RegExp Info
var textSearch:RegExp = new RegExp("-[A-Za-z]", "g");
searchResult = textSearch.exec(wxDataString);
trace(typeof(searchResult[0]));
strReplace(searchResult[0], "-", "_");
trace(searchResult);
strReplace(wxDataString, searchResult[0], sNew);
}
return wxDataString;
}
private function strReplace(str:String, search:String, replace:String):String {
return str.split(search).join(replace);
}
Thanks for any help you can give. Thank you very much.