Untested:

 

<mx:HTTPservice id="dsUniversal" resultFormat="e4x"
result="onResult(event)" ...>

 

private function getHTTPData(url:string,aParms:Array,sQueryId):void {
  var oResult:Object = new Object();

  var oParm:Object;

  for (var i:int=0; i<aParms.length;i++)  {

    oParm = aParms[i];

    oResult[oParm.name]  = oParm.value;

  }//for

  var atCall:AsyncToken = dsUniversal.send(oResult);

  atCall.sQueryId = sQueryId;
}//<mx:HTTPservice>

 

private function onResult(oEvent:ResultEvent):void  {

  var xmlResult = XML(oEvent.result);

  var sQueryId:String = oEvent.token;

  switch(sQueryId) {

    case "query1":

       doQuery1(xmlResult);

       break;

 

Get the picture?  I used array as the parms datatype for simplicity. As
long as you can loop over it to get the name=value pairs, xml would be
fine.

 

Tracy

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of oneproofdk
Sent: Friday, February 02, 2007 4:40 AM
To: [email protected]
Subject: [flexcoders] How to make a "universal" httpservice

 

I am fairly new to Flex2 and AS3, 4 weeks of programming/experimenting
under the hood.

In a application I am using several (6-7) httpservice calls, to
retrieve data for the various elements. Works great!

One thing that _really_ annoys me, is that I have several
<mx:HTTPservice> instances, one for each service I need to call.

This is a obviously not the correct way to do it, but what is ?

I imagine I could make a AS function that would accept some parameters
like :
function getHTTPData(url:string,parms:xml):object {
<!-- insert fantastic code here -->
}

Can anyone help me out here ??

Thanks for your time,
Mark

 

Reply via email to