3 Replies Latest reply on Jul 12, 2006 9:46 PM by isml

    Passing param in Httpservice

    isml
      I know i can use the request object in Httpservice to send name-vale pairs to the server.But my problem is not that. I need to remember an ID before HTTPservice.send() as when it results, i should use the ID to do something. But the server does not care about the ID, so if i store the ID in request object, it is redundant. And sometimes i need to remember one more value, the problem become even worse.The server does not use these information but i have to pay for the network cost. Originally I use global variables to solve the problem. It is a simple way but not the suitable one, as global variable is not recommended in any language.

      Is there a good solution?

      thanks in advance.
        • 1. Re: Passing param in Httpservice
          ntsiii Level 3
          You want to use the ACT pattern. I'll post a link below, but essentially what happens is that the send() method returns a "call" object. You can add any property you want to this object, string, id, number, even functions. When the result comes back, this call object is available to you in the result handler function, and you can get back whatever you put in.

          I usually just put in a string that identifies the query, and use a select statement to decide how to process it.

          Check out this example below.

          Tracy

          http://www.cflex.net/showfaq.cfm?Object=faq&channelID=1&faqtype=&defaultfields=&defaultVal ues=#Question372
          • 2. Re: Passing param in Httpservice
            isml Level 1
            oh, it's very wonderful.I appreciate your help very much.
            Actually, i found i had wrote ugly codes before.
            If i need to request httpservice twice, i orignally use two <mx:Httpservice> tag.As i do not know how to distinguish between each other.
            For example:
            If i need two name list, A and B

            <mx:HTTPService id="hsA" result="GetA()" />
            <mx:HTTPService id="hsB" result="GetB()" />

            In function GetA(), i do hsB.send().

            Now I wonder if i use only one HTTPService Object to solve the problem.
            I test much, but only find a even more ugly way.Here's my codes.

            In a Init function, i add an event listener to the hsA as i want to use "removeEventListener" later.

            var funDelegate:Function;
            function Init()
            {
            funDelegate = mx.utily.Delegate.create(this, GetA)
            hsA.addEventListener("result", funDelegate);
            hsA.send()
            }

            and in function GetA
            function GetA()
            {

            hsA.removeEventListener("result", funDelegate);
            funDelegate = mx.utily.Delegate.create("result", funDelegate);
            hsA.addEventListener("result", funDelegate);
            }

            Is it a suitable way?


            thanks in advance.
            • 3. Re: Passing param in Httpservice
              isml Level 1
              oh, i read the article you offerred and only to find i really wrote silly codes.I know how to cop with it.Thanks a lot