在Flex移动应用程序中无法使用Yahoo Weather API [英] could not be able to use yahoo weather api in flex mobile app
本文介绍了在Flex移动应用程序中无法使用Yahoo Weather API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在flex中获取Yahoo的天气信息,我想获取图像,我想获取所有当前状况,我的代码是:::
I want to get Yahoo weather info in flex I want to get image I want to get all of current conditions my code is:::
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:HTTPService id="weatherService"
url="{BASE_URL}"
resultFormat="object"
result="weatherService_resultHandler(event)"
fault="weatherService_faultHandler(event)"
showBusyCursor="true">
<s:request xmlns="">
<w>{woeidInput.text.toString()}</w>
</s:request>
</s:HTTPService>
</fx:Declarations>
<s:TextInput id="woeidInput" x="10" y="10" width="207" text="12744805"/>
<s:Button id="searchBtn" x="220" y="10" width="90" height="36" label="Search"/>
<s:Label id="cityName" x="134" y="82" height="17" fontSize="20" fontWeight="bold" text="Label"/>
<fx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private static const BASE_URL:String="http://weather.yahooapis.com/forecastrss?";
private static const WOEID:String="615702";
protected function weatherService_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
var result_weather_data:Object = event.result;
cityName.text=result_weather_data.title;
}
protected function weatherService_faultHandler(event:FaultEvent):void
{
// TODO Auto-generated method stub
}
]]>
</fx:Script>
请为我提供解决方案,我是Flex开发的新手
Please give me a solution in this matter I,m new to flex development
推荐答案
好,我知道了如何从yahoo weather rss获取一些信息. 在脚本块中,我已更改
Ok, I got Idea how to get some info from yahoo weather rss . In the script block I have changed
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:HTTPService id="weatherService"
url="{BASE_URL}"
resultFormat="e4x"
result="weatherService_resultHandler(event)"
fault="weatherService_faultHandler(event)"
showBusyCursor="true">
<s:request xmlns="">
<w>{woeidInput.text.toString()}</w>
</s:request>
</s:HTTPService>
</fx:Declarations>
现在在脚本块中,我是这样的:
now in script block I I did like this:
protected function weatherService_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
var result_weather_data_xml:XML = new XML(event.result);
var cityNameData:XMLList = result_weather_data_xml.descendants().attribute("city");
var countryNameData:XMLList = result_weather_data_xml.descendants().attribute("country");
var tempCData:XMLList = result_weather_data_xml.descendants().attribute("temp");
var descripData:XMLList = result_weather_data_xml.descendants().attribute("text");
var humidData:XMLList = result_weather_data_xml.descendants().attribute("humidity");
var image:String;
cityName.text=cityNameData + ", "+ countryNameData;
tempData.text = tempCData+"\u00B0"+"F";
descData.text = descripData[0];
HumidityData.text = humidData+"%";
}
,并且对于您想要在应用程序中使用的每件事,都要赋予属性(名称")
and for each thing which you want in in your app is to give attribute("NAME OF THING")
这篇关于在Flex移动应用程序中无法使用Yahoo Weather API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文