Flash中使用WebServiceConnector

      Flash&AS2 2006-1-24 16:17
以前公司做的一个WebServiceConnector例子,贴出来共享:
XML.prototype.ignoreWhite = true;

var res = function (ev) {
  initCityList(ev.target.results);
};
_root.myWS.addEventListener("result", res);

var subres = function (ev) {
  //initCityList(ev.target.results);
  trace(ev.target.results);
  initWeatherInfo(ev.target.results);
};
_root.subWS.addEventListener("result", subres);

function initCityList(res:String) {
  _root.test.text = res;
  var tempXML:XML;
  tempXML = new XML(_root.test.text);
  root = tempXML.firstChild;
  var nodeArray:Array = root.childNodes;
  for(var i=0; i<nodeArray.length; i++) {
    var one = nodeArray[i];
    //trace("cityName = " + one.childNodes[1].firstChild);
    _root.grid_content.addItem({国家:String(one.childNodes[0].firstChild),
                  城市:String(one.childNodes[1].firstChild)});
  }
}
var myListener = new Object();
var self = this;
myListener.cellPress = function(event) {
  var temp = grid_content.getItemAt(event.itemIndex);
  //trace(temp);
  _root.loadMoreInfo(temp.国家,temp.城市);
};
grid_content.addEventListener("cellPress", myListener);
function loadMoreInfo(country,city) {
  trace("country = " + country + " city = " + city);
  //var a:Array = new Array();
  //a["CountryName"] = String(country);
  //a["CityName"] = String(city);
  //_root.subWS.params = a;
  _root.ddd = new dd();
  ddd.CountryName = country;
  ddd.CityName = city;
  _root.subWS.params = ddd;
  _root.subWS.trigger();
};

function initWeatherInfo(res:String) {
  _root.test.text = res;
  var tempXML:XML;
  tempXML = new XML(_root.test.text);
  root = tempXML.firstChild;
  var nodeArray:Array = root.childNodes;
  _root.weather.text = "";
  _root.weather.text += "Location:      \n" + nodeArray[0].firstChild + "\n";
  _root.weather.text += "Time:        \n" + nodeArray[1].firstChild + "\n";
  _root.weather.text += "Wind:        \n" + nodeArray[2].firstChild + "\n";
  _root.weather.text += "Visibility:      \n" + nodeArray[3].firstChild + "\n";
  _root.weather.text += "SkyConditions:    \n" + nodeArray[4].firstChild + "\n";
  _root.weather.text += "Temperature:      \n" + nodeArray[5].firstChild + "\n";
  _root.weather.text += "DewPoint:      \n" + nodeArray[6].firstChild + "\n";
  _root.weather.text += "RelativeHumidity:  \n" + nodeArray[7].firstChild + "\n";
  _root.weather.text += "Pressure:      \n" + nodeArray[8].firstChild + "\n";
}
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}