4 Replies Latest reply on Dec 13, 2008 9:20 PM by ntsiii

    Using Sleep Function in Flex


      I have something here which takes some time for the HTTPService to communicate with an external server that hosts the database. The only issue here is that when I would like to change the view state to see the information, the application cannot handle it on the DataGrid due to the time lapse.

      In programming languages, there is a function called sleep that I can stop the program till certain stage is committed. In Flex, I tried to use setInterval(1000) to commit 10 seconds to put the program to sleep, but most manuals require me to apply setInterval with a function or two. Could I just do setInterval(1000) for my program to sleep for 10 seconds instead of waiting for it to apply to another function in Flex?

      Thanks in advance.

        • 1. Re: Using Sleep Function in Flex
          Hi Alice,

          You've got it wrong:) FP implements single thread event based model. So, when you make a call to HTTPService, you should not be waiting for response at all, instead, you should supply the event listener on result & failure events. And when data will be received, the function will be called.


          • 2. Re: Using Sleep Function in Flex
            SujitG Level 2

            As Dmitri mentioned, you should listen to the result event of the HTTPService. HTTPService calls to the server are asynchronous, so HTTPService will dispatch a result event when the response from the server is received.

            Please find more details on how to listen for result and fault events of the HTTPService at the URL below.


            You can also have a look at concept called Binding in Flex. This will allow you to bind your DataGrid to a ArrayCollection and when the ArrayCollection is modified, your DataGrid will reflect the changes. Please find more details on Binding at the URL below.


            Hope this helps.
            • 3. Re: Using Sleep Function in Flex
              alice_data Level 1

              I have been using this document you provided since I started using Flex, but I am not sure if I use something called progress bar or something would do me any good.

              The code itself in the back end does not contain errors, so I think even if I use result or failure in my HTTPService code, I still get a blank grid no matter what.

              I am attempting to allow users to edit the data entries after they get committed to the database, which I have to change the state for that. However, I have noticed that when I change the state to the view of which is supposed to extract the information from the database, the data itself does not seem to be committed yet. Would a progress bar help?
              • 4. Re: Using Sleep Function in Flex
                ntsiii Level 3
                No, a progress bar will not help with this.

                You must have a fault handler though. HTTPService will raise a fault if you do not call the back end correctly (bad url, or security problem, for example.)