5 Replies Latest reply on Nov 29, 2007 12:37 PM by ntsiii

    HTTPService error handling question

      When i am using HTTPService for Flex-PHP communication i set HTTPService's 'fault' property which handles error event. So basically if i have HTTPService set up like this:

      <mx:HTTPService id="test" url=" http://localhost/test/test.php" contentType="application/xml" useProxy="false" method="POST" fault="httpServiceError(event)">

      Then 'httpServiceError' method is fired in case of HTTPService error. What i would like to do in httpServiceError method is trace the id of the failed HTTPService. I tried with:

      public function httpServiceError(evt:FaultEvent):void{

      But soon realized that FaultEvent doesn't conatin 'currentTarget' property so this failed. What's the correct way to find out id of the failed HTTPService?

      thanks in advance,
      best regards
        • 1. Re: HTTPService error handling question
          atta707 Level 2
          Which version of flex are you on?

          I'm not sure about version 2 but in Flex 3 fault event does have currentTarget property. What do you get in the trace if you just say event.currentTarget?

          from the docs:

          The FAULT event type.

          The properties of the event object have the following values:

          Property Value
          bubbles false
          cancelable true, calling preventDefault() from the associated token's responder.fault method will prevent the service or operation from dispatching this event
          currentTarget The Object that defines the event listener that handles the event. For example, if you use myButton.addEventListener() to register an event listener, myButton is the value of the currentTarget.
          fault The Fault object that contains the details of what caused this event.
          message The Message associated with this event.
          target The Object that dispatched the event; it is not always the Object listening for the event. Use the currentTarget property to always access the Object listening for the event.
          token The token that represents the call to the method. Used in the asynchronous completion token pattern.


          • 2. Re: HTTPService error handling question
            msabljic Level 1
            As the matter of fact, i am also using Flex 3 but i obviously overlooked something in docs or maybe looked at Flex 2 docs. However, if i use HTTPService like i posted in first post and trace("evt.currentTarget:"+evt.currentTarget) in 'httpServiceError' which handles error then i get the following:

            [Object HTTPService]

            So i thought that's fine, trace(evt.currentTarget.id) should trace "test" in my example but instead i get the following error:

            Main Thread (Suspended: ReferenceError: Error #1069: Property id not found on mx.rpc.http.mxml.HTTPService and there is no default value.)

            Which i don't understand since i defined 'id' property :/
            • 3. Re: HTTPService error handling question
              atta707 Level 2
              id is not really a property at the HttpService, or any other MXML control for that matter, class. Unformatunatly, HttpService doesn't have name property either! So perhaps the best way for you would be to subclass it and add the name property which you can use to dertermine which service faulted.

              Hope this helps.

              • 4. Re: HTTPService error handling question
                msabljic Level 1
                I see, will do that. Thanks for help atta

                • 5. Re: HTTPService error handling question
                  ntsiii Level 3
                  So you have multiple HTTPService tags? Why not declare a different fault handler for each one?

                  You do not need multiple HTTPService instances, one will usually do.