Flex 天氣預報
效果如下截圖:

創建一個Flex項目weather
在weather.mxml中添加一個httpWebservice如下代碼:
<mx:HTTPService id="hs" url="http://www.google.com/ig/api?weather=Beijing" result="onResult(event)" resultFormat="e4x">
</mx:HTTPService>
定義一個onResult函數如下:
[Bindable]
private var xml:XMl=new XML();
private function onResult(e:ResultEvent):void{
xml=XML(e.result);
}
在weather.mxml中添加一個creationComplete="init()"函數
private function init():void{
hs.send();
}
然后再應用程序中添加一個TitleWindow控件,然后再添加一個TileList控件,如下:
<mx:TitleWindow x="173" y="238" width="432" height="235" title="北京" layout="absolute">
<mx:TileList x="10" y="10" width="392" height="175" dataProvider="{xml.weather.forecast_conditions}"
columnCount="4" itemRenderer="part1"></mx:TileList>
</mx:TitleWindow>
為titlelist創建一個項目渲染器part1如下:


浙公網安備 33010602011771號