9 Replies Latest reply on Dec 11, 2007 11:32 AM by paulfeuer

    HTTPService Timing Guidance

      A problem I've been having is dealing with the timing of an HTTPService call. I try to use the data before it actually arrives. What is the best technique to avoid this? How about when the data changes, is there a good way to "refresh" say, a label if it is supposed to change dynamically?
        • 1. Re: HTTPService Timing Guidance
          m_hartnett Level 3
          Use the showBusyCursor (service.showBusyCursor="true") to let the user know that something is happening.

          The best way to refresh a label is to bind its text to the model data your are retrieving. By binding the text of the label to the service call you don't have to call the .text value of the label it is done automatically.

          • 2. Re: HTTPService Timing Guidance
            bpapau Level 1
            Thanks for the advice!

            1) My timing problem is not a user issue. I am having problems updating a live chart. I plan to use a timer, but I'd like to be able to populate the charts without running into a syncing problem. Has anyone experienced this difficulty before?

            2) I'll look further into that.

            • 3. Re: HTTPService Timing Guidance
              m_hartnett Level 3
              This is a common problem and point of confusion.

              My approach was to create an ArrayCollection or Array that holds events. This objects needs to be maintained in a central location so that all objects can have access to it.

              If I need to execute a set of events sequentially I add all but the first event to the Array. I then execute the first event.

              The resultHandler in the service object would then check to see if anything is in the Array. If there are events in the Array then the next Event is retrieved and executed. The event is then taken out of the Array so that it is not executed again.

              This will occur untill all the events have been processed.
              • 4. Re: HTTPService Timing Guidance
                bpapau Level 1
                It is a very new concept for me (and I assume others) regarding "events". I am really enjoying the results I am getting using Flex/AS, but I'm finding good documentation hard to come by.... espessially concerning events.

                I have the Flex 2.0 Dev Guide, can you recommend anything else?

                Oh, BTW I managed to time it correctly by comparing two iterators (well, one is a "max" number and the other is the iterator).

                private function getData(timer:TimerEvent):void
                for(var Index:int = 0; Index < URLArray.URL.length ; Index++)
                var DB_Connect:Object = new Object;
                DB_Connect.marker = Index;
                var URL:String = new String;

                URL = URLArray.URL[Index]

                var _newData:Object = new Object;



                // the following function uses the DataArray references to populate each array individually.
                function dataReceived(evt:Object):void

                var param:Object = evt.token;
                // now add a for loop that goes through each chart and matches it up wth the data.
                for(var k:int = 0; k < Index; k++)
                if(param.marker == k)
                DataArray[k] = evt.result.data_point;
                if(k == Index - 1)

                • 5. Re: HTTPService Timing Guidance
                  m_hartnett Level 3
                  I didn't have to read that much about event based architecture because I have been doing java/swing for a while now so I dont really have any good links any info on events.

                  If you are new to Flex then I would concentrate on understanding:
                  how to build loosley coupled components
                  how to create and dispatch events.
                  how to use data binding to build a dynamic app.

                  The Cairngorm microarchitecture is also very useful in building applications. It helps you to adhere to the MVC design pattern.
                  This is kind of advanced and you don't really need to know how to use these objects until you learn Flex but you should keep it on your list. Here is a link to a real good paper on Cairngorm. http://www.adobe.com/devnet/flex/articles/cairngorm_pt1.html

                  Other than that I just downloaded a lot of sample apps and broke them down to figure out how they did stuff.
                  • 6. Re: HTTPService Timing Guidance
                    i had the same problem last month too. finally figured it out.

                    example here: http://xrumxrum.com/blog/2007/11/29/requestwaitload/
                    • 7. Re: HTTPService Timing Guidance
                      paulfeuer Level 1
                      bpapau - did you try adding an event listener to respond to the "result" event of the HTTPService? this event is fired when the response from the service is ready. you don't need a timer for it.

                      • 8. Re: HTTPService Timing Guidance
                        bpapau Level 1

                        I bacially just ordered it proporly to display the data after all children have been created. Its a bit of a rough hack, but it works ;)

                        I am using the result event to create the entire application, so I think that there still maybe some timing errors with that (although I can't really say the reason for it, only that I've experienced the problem).

                        I've added the Cairngorn to my fav's and will be reading it more tonight. Thanks!

                        I'd also like to ask a few follow ups: Why is there so little documentation out there for AS/Flex? It looks like this "Web 2.0" style of documentation includes a forum and some blogs. While thats a good supplement, it should be secondary to a big ol' book. I've had to try a number of scripts lately (PHP and Python) and they both have excellent documentation. Actionscript produces excellent results, but you really have to dig for an answer to the simplest question!

                        Just my opinion though...
                        • 9. Re: HTTPService Timing Guidance
                          paulfeuer Level 1
                          i agree with you about the docs. most of the examples online and in the books are for very simple things like shopping carts. almost everything in the app i've been working on has had to be overridden - including DataGrid, TileList, and ArrayCollection to name just a few. and the overrides are very peculiar and hacky to implement vary basic functionality - like single-click deselection of the last selected item in a TileList. or paging in an ArrayCollection.