One HTTPService instance will work fine.
Instantiate it with AS, or declare it in mxml as you choose.
Then, in the function where you are going to invoke the send(), you can any
properties you wish. The main property you will probably set is the url.
Instead of declaring the request object in mxml as you show, build it in AS
just before you invoke send()
You can also set a property on the AsyncToken, which you can then access in the
result handler function, in order to identify the result to perform the desired
processing.
Below are some snippets.
Tracy
Sample code using HTTPService, e4x, handler function to populate a list item.
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;
[Bindable]private var _xlcMyListData:XMLListCollection;
Invoke send:
var oRequest:Object = new Object();
oRequest.calDate = fmtDate.format(dateChoose.selectedDate);
oRequest._update = true;
var callToken:AsyncToken = service.send(oRequest);
token.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) {
case "myQuery1":
doWhatever(); //massage data, call
another query, whatever
break;
...
}
}//onResult
________________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of nylarch
Sent: Sunday, September 16, 2007 10:36 PM
To: [email protected]
Subject: [flexcoders] httpservice and crud
noob question alert.
Just starting on flex. I'm doing a simple CRUD page working with a calendar. Do
I need
to do seperate HTTPService components for the different CRUD operations or is
it possible
to dynamically pass in requests to one service since I'm doing all of the
operations on the
same backend php page.
i.e. do you need to seperate:
<mx:HTTPService id="getEvent" url="_calendar.php" resultFormat="text"
method="GET">
<mx:request>
<calDate>{fmtDate.format(dateChoose.selectedDate)}</calDate>
</mx:request>
</mx:HTTPService>
<mx:HTTPService id="updateEvent" url="_calendar.php" method="GET"
result="getEvent.send()">
<mx:request>
<calDate>{fmtDate.format(dateChoose.selectedDate)}</calDate>
<_update>true</_update>
</mx:request>
</mx:HTTPService>
or can I dynamically pass in the in "update=true" and just use one service for
both Get and
Update.
Thanks.