Flex4之HTTPService,读取天气预报

1.首先申明:

<mx:HTTPService  id="weatherService" url="http://192.168.17.6:8080/Smarter/weather"
result="jasononResultWeather(event)" resultFormat="e4x">
</mx:HTTPService>


这里意为在服务器后台读取webservice,然后再通过HttpService在客户端呈现出来.


2.然后要以在applicationWeather_creationCompleteHandler进行调用。

protected function applicationWeather_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
weatherService.send();

///this.setStyle("backgroundAlpha",0);

}


3.而applicationWeather_creationCompleteHandler在

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
  xmlns:s="library://ns.adobe.com/flex/spark"
  xmlns:mx="library://ns.adobe.com/flex/mx"
  xmlns:halo="library://ns.adobe.com/flex/halo"
  minWidth="955" minHeight="600" width="1364" height="766" creationComplete="init();initApp();initjason();"                                 initialize="applicationWeather_creationCompleteHandler(event);"
  xmlns:flexiframe1="com.google.code.flexiframe.*"
  xmlns:marquee="com.bc.mar.app.*"   
  >

进行申明。

4.它的处理函数jasononResultWeather实现细节如下所示:

private function jasononResultWeather(e:ResultEvent):void{
var data:String = new String(e.result);

//分解成字符串数组
var dataArr:Array=data.split(",");
//Alert.show("数组的长度:\t"+dataArr.length);
// Alert.show("hello world");
//Alert.show(data.toString());
//0.广州,    
//1.tqimgs/a_3.gif,   
//2.阵雨转大雨, 
//3.25℃/31℃, 
//4.湿度:92%

// Alert.show(data.toString());
if(dataArr.length!=0){
weatherImg.source=urlWeather1+dataArr[1];
todayWeather.text=dataArr[2];
todayDegree.text=dataArr[3];
}
else{
Alert.show("暂无天气");
}

}


这样就可以获取天气预报了。并呈现在客户端了、。



你可能感兴趣的:(String,webservice,function,Flex,application,library)