0

I'm using AS3 and Flash CC. I'm trying to build a simple weather widget, but I can't seem to parse through any of the XML data from the Yahoo Weather API. The XML data loads, and you can see it in the output when I trace the entirety of the XML data.

Here is the code I'm using in frame 1 action script of my fla file:

var myXML: XML = new XML();
var XML_URL: String = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22nome%2C%20ak%22)&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";

var myXMLURL: URLRequest = new URLRequest(XML_URL);
var myLoader: URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(event: Event): void {
    myXML = XML(myLoader.data);
    trace("Data loaded.");
    var yweather:Namespace = new Namespace("http://xml.weather.yahoo.com/ns/rss/1.0");
    trace(myXML);   //successfully shows entire XML data
    trace(myXML.query.results.channel.description);  //unsuccessful
    trace(myXML.channel.item.yweather::condition.@temp + " °F"); //only shows °F
}

Does anyone know why I am unable to return specific XML data like the temperature? Thanks in advance!

Note: I used this tutorial as a foundation for this.

1 Answers1

1

Ugh. It was as simple as moving through the data incorrectly based on the tutorial since my xml was coming in differently with a results level. If anyone runs into this issue, the root level of the XML data needs to be ignored. In my case, you ignore "query" and begin at "results":

Incorrect:

  • Unsuccessful because I included query

    trace(myXML.query.results.channel.description);
    
  • Unsuccessful because I didn't include results

    trace(myXML.channel.item.yweather::condition.@temp + " °F");
    

Corrected:

trace(myXML.results.channel.description);
trace(myXML.results.channel.item.yweather::condition.@temp + " °F");

Alternatively, I could have used the URL: http://weather.yahooapis.com/forecastrss?w=2460286 and my original code taken from the tutorial for temp would have worked:

trace(myXML.channel.item.yweather::condition.@temp + " °F");

And the code for description would work from the channel level as well:

trace(myXML.channel.description);

Hope this helps anyone with this issue!