2013-12-19 42 views
0

我想推出的HTTPService之前顯示BusyIndi​​cator控件,並隱藏在RPC完成:BusyIndi​​cator控件不顯示

<?xml version="1.0" encoding="utf-8"?> 
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:mx="library://ns.adobe.com/flex/mx" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     title="Saisie et envoi" 
     creationComplete="creationCompleteHandler(event)" > 

    <fx:Declarations> 
     <!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). --> 
     <mx:HTTPService id="userRequest" url="{url}/crr.php" resultFormat="text" result="userRequest_resultHandler(event)" useProxy="false" method="POST" /> 
    </fx:Declarations> 

    <fx:Script> 
     <![CDATA[ 
      import mx.events.FlexEvent; 
      import mx.rpc.events.ResultEvent; 

      import model.Config; 
      import model.Db; 

      var conf:Config = new Config(); 
      public var db:Db = new Db(); 

      [Bindable] 
      public var url:String = conf.getConfigSo("url"); // example : http://localhost/myfolder 

      protected function enregistrer(event:MouseEvent):void 
      { 
       var param:Object = new Object(); 
       try { 
        if (db.avoirAttribut("enreg")) { 
         db.setDbSo("enreg", db.getDbSo("enreg")+chp1.text+";"+chp2.text+"\n"); 
        } 
        else { 
         db.setDbSo("enreg", chp1.text+";"+chp2.text+"\n"); 
        } 
        param.text = "Enregistrement effectué avec succès !"; 
        navigator.pushView(Message, param); 
       } 
       catch (e:Error) { 
        param.text = "Enregistrement non effectué !"; 
        navigator.pushView(Message, param); 
       } 
      } 

      protected function lire(event:MouseEvent):void 
      { 
       area.text = db.getDbSo("enreg"); 
      } 

      protected function send(event:MouseEvent):void 
      { 
       busy.visible = true; 
       userRequest.cancel(); 
       var params:Object = new Object(); 
       params.col1 = db.getDbSo("enreg"); 
       userRequest.send(params); 
       busy.visible = false; 
      } 

      protected function userRequest_resultHandler(event:ResultEvent):void 
      { 
       resultHTTP.text = userRequest.lastResult.toString(); 
      } 

      protected function creationCompleteHandler(event:FlexEvent):void 
      { 
       chp1.setFocus(); 
      } 

     ]]> 
    </fx:Script> 

    <s:Scroller width="100%" height="100%"> 
     <s:VGroup width="100%" height="100%" paddingTop="5" paddingBottom="5" verticalAlign="middle" horizontalAlign="center" gap="5"> 
      <s:TextInput id="chp1" width="50%"/> 
      <s:TextInput id="chp2" width="50%"/> 
      <s:Button label="Enregistrer" click="enregistrer(event)"/> 
      <s:Button label="Lire" click="lire(event)"/> 
      <s:TextArea id="area" editable="false"/> 
      <s:Button label="Envoyer" click="send(event)"/> 
      <s:BusyIndicator id="busy" symbolColor="blue" visible="false" /> 
      <s:Label id="resultHTTP"/> 
     </s:VGroup> 
    </s:Scroller> 

</s:View> 

的問題是,在運行時,BusyIndi​​cator控件沒有顯示,但我知道,整個操作完成需要幾秒鐘的時間。那麼爲什麼在這種情況下不顯示BusyIndi​​cator?

回答

4

HTTPService請求send()在請求發送時返回,而不是在收到響應時返回。所以你只在短時間內顯示繁忙指示器(實際上根本不顯示,因爲渲染是在下一個顯示週期完成的......)

你需要做的是使指示器可見在發送函數中,但是隱藏結果處理程序中的指示符。 (您也應該爲錯誤處理程序執行此操作,否則如果請求中存在錯誤,指示器仍然可見)

相關問題