???? ?網絡狀況是互聯網發展與軟件發展的一個很大的瓶頸,如果哪天訪問網上資源能象訪問本地硬盤,或者能象訪問內存那樣快,那樣咱們的計算機以后只需要輸入輸出設備以及網絡設備就可以了,哈哈,這只是一個美好的愿望。
???? ?Flex應用在Web開發上,避免不了網絡問題,下面的說明如何在加載數據時顯示Loading狀態,剛剛接觸Flex不久,歡迎拍磚。
?
????? 原理是這樣的,首先定義了兩一個ViewState,其中一個就是Loading狀態,當點擊按鈕的時候就顯示這個Loading視圖,直到數據加載完之顯示數據的視圖。?
?
????? 先看效果圖片:
????? 首先,點擊了按鈕之后就會由于網絡問題顯示一個遮罩,上面用了一個Label顯示Loading...字樣,當然這里可以用任何更加漂亮的東西替換,比如GIF的圖片。這里的網絡問題由于是在自己的機器上測試,是人為造成的,我的服務器代碼是使用的JAVA,在服務器上延遲了三秒加載數據。
?????
?????
?
三秒之后顯示:
?
??????
?
代碼:
?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:states>
<!--加載視圖,可以自己制作加載畫面,
這個例子就只用了一個LABEL表示一下正在加載-->
<!--數據加載成功后的State-->
<mx:State name="ListState">
<mx:AddChild relativeTo="{pl}" position="lastChild">
<mx:Canvas id="can" width="100%" height="100%">
<mx:DataGrid id="dg" horizontalCenter="0" width="100%" height="100%" >
<mx:columns>
<mx:DataGridColumn headerText="Id" dataField="p_id"/>
<mx:DataGridColumn headerText="Title" dataField="p_title"/>
</mx:columns>
</mx:DataGrid>
</mx:Canvas>
</mx:AddChild>
</mx:State>
<!--加載狀態的視圖-->
<mx:State name="LoadingState" basedOn="ListState">
<mx:AddChild relativeTo="{can}" position="lastChild">
<mx:Canvas id="shade" width="100%" height="100%"
backgroundColor="blue" backgroundAlpha="0.1">
<mx:Label text="Loading..." horizontalCenter="0" verticalCenter="0" fontSize="14"/>
</mx:Canvas>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:Script>
<![CDATA[
import mx.rpc.AsyncToken;
public function listLoad() {
this.currentState = "LoadingState";
//var loadListResponder:LoadListResponder = new LoadListResponder(this, this.dg);
//var token:AsyncToken = listLoadService.send();
//token.addResponder(loadListResponder);
listLoadService.send();
}
]]>
</mx:Script>
<mx:HTTPService id="listLoadService"
url="http://...."
method="post">
<mx:result>
<![CDATA[
this.dg.dataProvider = listLoadService.lastResult.data.problems.problem;
this.currentState = "ListState";
]]>
</mx:result>
</mx:HTTPService>
<mx:Panel id="pl" title="lOAding..." width="400" height="300">
</mx:Panel>
<mx:Button x="10" y="333" label="Load Data" click="listLoad()"/>
</mx:Application>
?
?
?
參考文章:
?Show Flex Datagrid as busy while loading and reloading
?
問題:
?
I am using showbusycursor on my HTTPService so that while the datagid is loading is that the? cursor at least changes but I would like to do more like graying out the datagrid or something. ?But I am not sure where to start I tried:
?????? ?????<mx:DataGrid dataProvider="{repRoleUsersXLC}" width="100%" height="90%"
?????? ??????????? ?????? ? ? ? ? ? ? ? ?id="AssUsersDG"
?????? ??????????? ?????? ? ? ? ? ? ? ? ?updateComplete="this.enabled=true"
?????? ??????????? ?????? ? ? ? ? ? ? ? ?creationComplete="this.enabled=false"/>
but it didn't do as expected it disabled the scroll bar but I hoped it would disable grid. ?But I would like to do something that is really clear the data grid is loading and reloading thanks for any help.
?
回答:
?
<mx:DataGrid dataProvider="{repRoleUsersXLC}" width="100%" height="90%"
id="AssUsersDG"
updateComplete="currentState=null"
creationComplete="currentState='loading'"/>
?
?
?
????
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

