Question

I would like to reuse a s:HTTPService component if possible. I am having trouble understanding how to pass a parameter to the service call so the result function can be changed.

For example,

functOne(), HTTPService result = "FunctOneRtn(event)"
functTwo(), HTTPService result = "FunctTwoRtn(event)"

flex 4.6

<fx:Declarations>
    <s:HTTPService id="myCall" url="http://myUrl.com/"
                   useProxy="false" method="POST" result=funct***Rtn(event) >
    </s:HTTPService>
</fx:Declarations>
<fx:Script>
    <![CDATA[
        import mx.rpc.events.ResultEvent;
        private function functOne() :void
        {
            var params:Object = new Object();
            /* call FuntOneRtn */       
            myCall.send(params);
        }
                    private function functTwo() :void
        {
            var params:Object = new Object();
            /* call FuntTwoRtn */       
            myCall.send(params);
        }

        public function FunctOneRtn(event:ResultEvent) : void{
            // Do Some Stuff
        }
                    public function FunctTwoRtn(event:ResultEvent) : void{
            // Do Some Stuff
        }




    ]]>
</fx:Script>

thx Art

Was it helpful?

Solution

You can not pass a parameter to the HTTPService but you can can change the handler function for different requests. This is a sample

<fx:Declarations>
<s:HTTPService id="myCall" url="http://myUrl.com/"
               useProxy="false" method="POST">
</s:HTTPService>
</fx:Declarations>

private function functOne():void
{
       myCall.addEventListener("result",FunctOneRtn);
}
private function functTwo():void
{
       mycall.removeEventListner("result",FunctOneRtn);
       myCall.addEventListener("result",FunctTwoRtn);
}
private function FunctOneRtn(event:ResultEvent)
{
    //handle function one result
}
private function FunctTwoRtn(event:ResultEvent)
{
    //handle function two result
}     

Then You can call functOne() and functTwo() as you like

OTHER TIPS

I believe we will have only one ResultEvent function, you have to write the logic to differentiate the results you get from the ResultEvent for first and second call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top