RSS feeds like Yahoo! weather have data that can't be retrieved by using the regular XML class
Using the Namespace class will give you access to data inside an RSS feed
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
<mx:Script>
<![CDATA[
import flash.events.MouseEvent;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
private var _weatherURL:String = "http://weather.yahooapis.com/forecastrss?p=";
private var _weatherLoader:URLLoader;
private var _xmlResult:XML;
private function init():void
{
_weatherLoader = new URLLoader();
submitButton.addEventListener(MouseEvent.CLICK, sendZip);
}
private function sendZip(evt:MouseEvent):void
{
if(zipField.text != "")
{
_weatherLoader.load(new URLRequest(_weatherURL+zipField.text));
_weatherLoader.addEventListener(Event.COMPLETE, parseResults);
}else
{
instructionField.text = "Please Enter a Zip Code";
}
}
private function parseResults(evt:Event):void
{
_xmlResult = new XML(evt.target.data);
var yweather:Namespace = new Namespace("http://xml.weather.yahoo.com/ns/rss/1.0");
//see every node called forcast
//trace(_xmlResult..item.yweather::forecast);
//trace(_xmlResult..item.yweather::forecast[0].@day);
header.text = _xmlResult..title[0];
currentConditions.text = _xmlResult..title[2];
//load htmlresults into AIR App
//weatherInfo.width = 300;
//weatherInfo.height = 200;
//weatherInfo.htmlText = _xmlResult..description[1];
forcastArea.text = "Forcast for: ";
forcastArea.text+= "\n"+_xmlResult..item.yweather::forecast[0].@day +" " + _xmlResult..item.yweather::forecast[0].@date +" " + _xmlResult..item.yweather::forecast[0].@low +" " + _xmlResult..item.yweather::forecast[0].@high +" " + _xmlResult..item.yweather::forecast[0].@text;
forcastArea.text+= "\n";
forcastArea.text+= "\n";
forcastArea.text+= "\n"+ "Forcast for: ";
forcastArea.text+= "\n"+_xmlResult..item.yweather::forecast[1].@day +" " + _xmlResult..item.yweather::forecast[1].@date +" " + _xmlResult..item.yweather::forecast[1].@low +" " + _xmlResult..item.yweather::forecast[1].@high +" " + _xmlResult..item.yweather::forecast[1].@text;
}
]]>
</mx:Script>
<mx:VBox width="100%" height="100%" verticalAlign="middle" horizontalAlign="center">
<mx:Text id="header" />
<!--mx:HTML id="weatherInfo"/-->
<mx:TextArea id="forcastArea" width="300" height="100" backgroundAlpha="0" borderStyle="none"/>
<mx:Text id="currentConditions"/>
<mx:Text id="forcast"/>
<mx:Text id="instructionField" text="Enter Zip Code for Weather"/>
<mx:TextInput id="zipField" />
<mx:Button id="submitButton" label="Submit Zip Code"/>
</mx:VBox>
</mx:WindowedApplication>