Note, you might find it easier to works with a single HTTPService instance
and a single result handler.  You can use AsyncToken to associate some
result with its call.  There are many options, but one simple way is to
assign a string value to a property on the token, like , token.callid =
"callOne"; In the handler, you can access the value of "called".  I use a
switch statement to control result processing.  This approach makes it easy
to debug; all results will hit a breakpoint in the handler.

 

Here are some snippets that show 'daisy chaining".

Sample code using HTTPService, e4x, handler function to populate a DataGrid.


Also shows usage of AsyncToken.

 

The DataGrid tag:

<mx:DataGrid id="dg" dataProvider="{_xlcMyListData}" .../>

 

 

The HTTPService tag:

<mx:HTTPService id="service" resultFormat="e4x" result="onResult(event)"
fault="..../>

 

Script block declaration:

import mx.rpc.Events.ResultEvent;

import mx.rpc.AsyncToken;

 

 

[Bindable]private var _xlcMyListData:XMLListCollection;

 

Invoke send:

var oRequest:Object = new Object();

oRequest.Arg1 = "value1";

var callToken:AsyncToken = service.send(oRequest);

callToken.callId = "myQuery1";

 

Result Handler function:

private function onResult(oEvent:ResultEvent):void  {

  var xmlResult:XML = XML(event.result);                //converts result
Object to XML. can also use "as" operator

  var xlMyListData:XMLList = xmlResult.myListData;      //depends on xml
format, is row data

  _xlcMyListData = new XMLListCollection(xlMyListData); //wrap the XMLList
in a collection

  trace(_xlcMyListData.toXMLString());                  //so you can see
exactly how to specify dataField or build labelFunction

  var callToken:AsyncToken = oEvent.token;

  var sCallId = callToken.callId;                       //"myQuery1"

  switch(sCallId)  {                                    //Process the result
conditionally

    case "myQuery1":

      doQuery2();                                       //do whatever. this
example calls another data service query

      break;

    ... 

  }

}//onResult

 

Tracy Spratt,

Lariat Services, development services available

  _____  

From: [email protected] [mailto:[email protected]] On
Behalf Of Matthew A. Wilson
Sent: Thursday, April 09, 2009 10:35 AM
To: [email protected]
Subject: [flexcoders] Re: Debugger won't break on HTTP Service result
function

 






Well, I figured it out. I'm fairly new to Flex so please hold your laughter.
What happened is that I was calling 3 HTTPService requests to the database
and then calling an internal function to work with the data I had received.
What I didn't realize was that Flex makes those calls asynchronously (I
know, I know - stop laughing).

So, I was hitting an error in my internal function because it was trying to
work with an XMLListCollection that hadn't been populated yet (it was null).
I would put a breakpoint in my result function, but of course, the Flex app
had already tripped up before the results were returned.

So now I'm "daisy-chaining" my HTTPServices so that the 2nd one is called
from within the 1st calls result function. And the 3rd within the 2nd, and
then finally calling my internal function from within the 3rd result
function...if that makes any sense.

Anyway, thanks for everyone's help. Have a great day!

--- In flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com,
"valdhor" <valdhorli...@...> wrote:
>
> Have you set up another event listener (using Actionscript) that is
grabbing that event?
> 
> 
> --- In flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com,
"Matthew A. Wilson" <korband@> wrote:
> >
> > I have a component that I'm adding to my Flex project and it makes 3
HTTP Service calls. On the result="" I have listed a function and inside
that function I have created a breakpoint.
> > 
> > When I go into debug, it won't stop at that breakpoint. It's like it's
not calling the result function. I know that the app is making the calls and
getting the resulting XML (using Firebug). I can set a breakpoint anywhere
else in the app and it will stop...just not on the result or fault HTTP
service functions.
> > 
> > Also, I only have this problem on this one component. This doesn't
happen anywhere else in the application. I would paste some code in here for
you to evaluate - but I doubt it will be useful. If I change the name of the
function in the result="" then Flex warns me that I'm referencing a function
that doesn't exist. So when I retype it to match the function below...the
warning disappears.
> > 
> > The only other thing I can mention is that I "accidentally" installed
Flash 10 player, so I uninstalled and then installed Flash 9 Active-X
Debugger. But again...I only have this issue on one component.
> > 
> > Any initial thoughts/ideas?
> > 
> > Thanks to all!
> >
>



Reply via email to