在AS3中获取yahoo weather xml中的风

时间:2016-04-20 08:29:01

标签: xml actionscript-3 flash

Yahoo Weather已更改其天气查询的XML地址。

以前它是这样的:
http://xml.weather.yahoo.com/forecastrss/
现在它变成了:
https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid=

所以,在我的AS3中,我正在获取风向和风向,但现在它似乎不适用于新链接。例如:通过以下链接,我们可以查询XML的风速和风向:

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid=1049640%20AND%20u=%22f%22

从返回的XML中,所需条目如下所示:<yweather:wind speed="3" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" direction="80" chill="80"/>

我的AS3代码是:

var url:String;
url = 'https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid=1049640 AND u="f"';
var yahooWeatherXML:URLRequest = new URLRequest(url)
var urlLoader:URLLoader = new URLLoader(yahooWeatherXML);
urlLoader.addEventListener(Event.COMPLETE,weatherLoaded);



        function weatherLoaded(e:Event):void{
    xml = new XML(e.target.data);
    var cityTxt = xml.channel.yweather::location.@city;
    var windD = xml.channel.yweather::wind.@direction;

var windTxt = "Wind: "+ (Math.round(xml.channel.yweather::wind.@speed/1.852)+"nd");


urlLoader.load(yahooWeatherXML);

    accueil.info_txt.text = windTxt +" "+windDirectionTxt;
urlLoader.removeEventListener(Event.COMPLETE,weatherLoaded);
 }

知道可能是什么问题吗?

0 个答案:

没有答案