加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex4之HTTPService,读取天气预报

发布时间:2020-12-15 01:10:40 所属栏目:百科 来源:网络整理
导读:1.首先申明: mx:HTTPService ?id="weatherService" url="http://192.168.17.6:8080/Smarter/weather" result=" jasononResultWeather (event)" resultFormat="e4x" /mx:HTTPService 这里意为在服务器后台读取webservice,然后再通过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("暂无天气");
}

}


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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读