5 Replies Latest reply on Feb 19, 2009 10:11 AM by PeakDigital

    HTTPService - addEventListener vs ResultEvent function?

    PeakDigital
      I am still working on understanding the basic concepts and flow of Flex. I understand that it is asynchronous, and relies on a multitude of events, which will take a lot of re-thinking the way I usually do things but will be great once I learn it.

      My current project involves looping through an ArrayCollection and calling a PHP HTTPService for each row. Since the Flex code isn't waiting for a call to complete before sending the next, I worry it eventually could overload the server with concurrent requests.

      Right now I am trying to comprehend the functional difference between using addEventListener in the HTTPService compared to using a handler function defined in the HTTPService result property like I currently use (code is below) . My goal is to know when one service call has been completed, then execute the service for the next row.

      I have been doing a lot of reading and research on this but haven't found a clear answer yet. Am I correct in thinking the result handler code does not execute until the HTTPService call is complete and the result or fault is returned?

      Thank you for your assistance.
        • 1. Re: HTTPService - addEventListener vs ResultEvent function?
          Level 7
          There is very little actual difference between using addEventListener
          and using the handler function on result. In fact, you can think of the
          following things as being equivalent:

          <mx:HTTPService id="serviceSendEmail" result="handlerSendEmail(event)" />

          and

          var serviceSendEmail:HTTPService = new HTTPService();
          serviceSendEmail.id = "serviceSendEmail";
          serviceSendEmail.addEventListener(ResultEvent.RESULT, function
          (event:ResultEvent):void {handlerSendEmail(event)});

          Of course, if you were to actually use addEventListener, you'd just want
          to use:

          serviceSendEmail.addEventListener(ResultEvent.RESULT, handlerSendEmail);

          All MXML is actually converted to ActionScript, so which you use is a
          matter of which is more convenient to you. Both will wait to execute the
          handlerSendEmail function until after the data has been obtained from
          the server, or will call the fault handler after a fault is returned.
          • 2. Re: HTTPService - addEventListener vs ResultEvent function?
            Level 7

            "PeakD" <webforumsuser@macromedia.com> wrote in message
            news:gnfqof$12r$1@forums.macromedia.com...
            >I am still working on understanding the basic concepts and flow of Flex. I
            > understand that it is asynchronous, and relies on a multitude of events,
            > which
            > will take a lot of re-thinking the way I usually do things but will be
            > great
            > once I learn it.
            >
            > My current project involves looping through an ArrayCollection and calling
            > a
            > PHP HTTPService for each row. Since the Flex code isn't waiting for a call
            > to
            > complete before sending the next, I worry it eventually could overload the
            > server with concurrent requests.

            If you go into phpmyAdmin and use the interface to add multiple records to
            your table at once, when it shows you what sql it used to add the rows, you
            will see that you don't have to add records one at a time...


            • 3. HTTPService - addEventListener vs ResultEvent function?
              PeakDigital Level 1
              Nate, Thank you for that clarification. That gives me one more little step forward in my learning.

              ------

              Amy, Thank you for the tip on multiple insertions to MySQL. I discovered that a few months ago and it is a big help. In this case my PHP is not communicating to the database but rather executing mail commands.
              • 4. Re: HTTPService - addEventListener vs ResultEvent function?
                Level 7

                "PeakD" <webforumsuser@macromedia.com> wrote in message
                news:gng6gk$e3q$1@forums.macromedia.com...
                > Nate, Thank you for that clarification. That gives me one more little step
                > forward in me learning.
                >
                > ------
                >
                > Amy, Thank you for the tip on multiple insertions to MySQL. I discovered
                > that
                > a few months ago and it is a big help. In this case my PHP is not
                > communicating
                > to the database but rather executing mail commands.

                You could still send the stuff to PHP in a batch.


                • 5. Re: HTTPService - addEventListener vs ResultEvent function?
                  PeakDigital Level 1
                  Amy, That is true. I had originally built this project in PHP but had problems with it running into the timeout limits on my server. My main reason for moving to Flex was so that I could execute the PHP mail script without running into that timeout problem. Now that I have it working one at a time and have logged the amount of time required for a single execution, I will probably use your advice and send the addresses in an array, just limited to a number that I know will be able to be processed inside the server's time limit. Thank you.