方法很简单,用UDDI查找到提供天气的webSerivse的WSDL,然后查看它公开的方法.调用方法,代码最主要是显视它而已
(虽然不是我的作品.但原理很简单```)
stop();
import mx.services.WebService;
import mx.controls.Alert;
//定义WS的路径;
var ws_url:String = "http://www.klstudio.com/cfc/weather.cfc?wsdl";
//定义WS对象;
var ws:WebService = new WebService(ws_url);
//设置本地保存对象;
var save_status_so:SharedObject = SharedObject.getLocal("weather_kinglong_so", "/");
//返回的天气对象;
var weatherObj:Object;
//获取本地保存的城市名;
function getSaveStatus():String {
return (save_status_so.data.city == undefined) ? "上海" : save_status_so.data.city;
}
//保存当前选择的城市名;
function setSaveStatus(_ct:String):Void {
save_status_so.data.city = _ct;
save_status_so.flush();
}
var cb_listener:Object = new Object();
cb_listener.change = function(et:Object) {
_root.setCityWeatherView(et.target.selectedItem.data);
};
//显示城市显示;
function setCityView(_select:String) {
var select_id:Number = 0;
var select_ws:String;
city_cb.removeAll();
var j:Number = 0;
for (var i in weatherObj) {
city_cb.addItem(weatherObj[i].WEATHER_CITY, i);
if (weatherObj[i].WEATHER_CITY == _select) {
select_id = j;
select_ws = i;
}
j++;
}
city_cb.selectedIndex = select_id;
city_cb.addEventListener("change", cb_listener);
setCityWeatherView(select_ws);
}
//显示城市天气;
function setCityWeatherView(_id:String):Void {
setSaveStatus(weatherObj[_id].WEATHER_CITY);
var publish_date:Date = weatherObj[_id].WEATHER_DATE;
var show_date:Date = new Date(publish_date.getFullYear(), publish_date.getMonth(), publish_date.getDate()+1);
date_txt.text = (publish_date.getMonth()+1)+"月"+publish_date.getDate()+"日"+"~"+(show_date.getMonth()+1)+"月"+show_date.getDate()+"日";
wt_txt.text = "天气情况:"+weatherObj[_id].WEATHER_WT;
wd_txt.text = "风向:"+weatherObj[_id].WEATHER_WD;
ws_txt.text = "风力:"+weatherObj[_id].WEATHER_WS;
tp_txt.text = "气温:"+weatherObj[_id].WEATHER_TP;
var month_str = (publish_date.getMonth()>8) ? String(publish_date.getMonth()+1) : "0"+String(publish_date.getMonth()+1);
var date_str = (publish_date.getDate()>9) ? String(publish_date.getDate()) : "0"+String(publish_date.getDate());
var hours_str = (publish_date.getHours()>9) ? String(publish_date.getHours()) : "0"+String(publish_date.getHours());
var min_str = (publish_date.getMinutes()>9) ? String(publish_date.getMinutes()) : "0"+String(publish_date.getMinutes());
update_txt.text = publish_date.getFullYear()+"/"+month_str+"/"+date_str+" "+hours_str+":"+min_str+":00";
//right_txt.htmlText = " Powered by <b><a href='http://www.klstudio.com' target='_blank'><font color='#5B7C91'>klstudio.com</font></a></b>";
}
//执行查询语句;
function getListCityWeather() {
date_mc.setShow(true);
city_cb.enabled = false;
date_mc.setLabel("正在调入气象数据");
var callObj = ws.getListCityWeather();
callObj.onResult = function(result) {
_root.setCityWeather(result);
};
}
//显示查询结果;
function setCityWeather(_obj:Object):Void {
date_mc.setShow(false);
city_cb.enabled = true;
weatherObj = _obj;
setCityView(getSaveStatus());
}
myClickHandler = function (evt) {
switch (evt.detail) {
case Alert.YES :
_root.getListCityWeather();
break;
case Alert.NO :
break;
}
};
//显示提示信息;
function setAlert(_info:String):Void {
Alert.yesLabel = "是";
Alert.noLabel = "否";
Alert.show(_info, "提示信息", Alert.YES | Alert.NO, _root, myClickHandler);
}
getListCityWeather();
回复Comments
{commenttime}{commentauthor}
{CommentUrl}
{commentcontent}