我想从 free.worldweatheronline.com 获取 xml 数据,我尝试了以下方式:-
<fx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private var main_xml_url:String = "http://free.worldweatheronline.com/feed/weather.ashx?q="+cityName.text.toString()+"&format=xml&num_of_days=2&key=my_api_key"; // there I put my api key not showing here//
protected function weatherService_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
var result_weather_data:Object = event.result;
cityNameData.text = data.request.query;
}
protected function weatherService_faultHandler(event:FaultEvent):void
{
// TODO Auto-generated method stub
cityNameData.text = event.message.toString();
}
]]>
</fx:Script>
<fx:Declarations>
<s:HTTPService id="weatherService"
url="main_xml_url"
resultFormat="object"
result="weatherService_resultHandler(event)"
fault="weatherService_faultHandler(event)"/>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:TextInput id="cityName" text="Hyderabad" x="10" y="10" width="219" fontWeight="bold" prompt="Enter city Name"/>
<s:Label id="cityNameData" x="108" y="109" width="202" fontSize="20" fontWeight="bold"/>
但是有一个错误说:无法访问空对象引用的属性或方法。在私有 var main_xml_url:String
请通过解决它来帮个忙 提前谢谢。