没有显示BusyIndi​​cator

时间:2013-12-19 08:47:43

标签: flex flex-mobile

我想在启动HTTPService之前显示busyIndi​​cator,并在rpc完成时隐藏它:

<?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?

1 个答案:

答案 0 :(得分:4)

HTTPService请求send()在发送请求时返回,而不是在收到响应时返回。所以你只是在很短的时间内显示忙碌指标(实际上根本没有,因为渲染是在下一个显示周期完成的......)

您需要做的是在发送功能中使指示符可见,但在结果处理程序中隐藏指示符。 (您也应该为错误处理程序执行此操作,否则如果请求中存在错误,指示符仍然可见)