That should work, I use dynamic urls with HTTPService regularly.  One
suggestion, don't use binding. Instead, in the function where you invoke
service.send(), set the url there.

 

Additionally, unless you have a very special use case, you do not want
resultFormat="xml", you want resultFormat="e4x".  "xml" is the old AS
object, and lacks most of the functionality available in e4x.

 

  _____  

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of anitha2324
Sent: Saturday, March 07, 2009 2:35 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] how to call dynamic servlet

 

Hi All,

i have made a servelt which returns details in xml format ,
this is servlet is working fine if am calling it from flex in static way
like this

<mx:HTTPService id="topSenders" useProxy="false" resultFormat="xml"
method="POST" url="http://localhost:
<http://localhost:8080/Application/topSenderServlet?TYPE=4&amp;USER_ID=12>
8080/Application/topSenderServlet?TYPE=4&amp;USER_ID=12" 
result="serv_result(event);"/>

but if i tried to call the servlet like this

<mx:HTTPService id="topSenders" useProxy="false" resultFormat="xml"
method="POST" url="{servletURL}" 
result="serv_result(event);"/>

then it is not working , am not getting any error

here is the full code for my mxml file

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe. <http://www.adobe.com/2006/mxml>
com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import flash.net.sendToURL;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.xml.SimpleXMLDecoder;
import mx.controls.Button;
import mx.controls.Label;
import mx.collections.ArrayCollection;

[Bindable]
public var expenses:ArrayCollection;

[Bindable]
public var userId:int;
[Bindable]
public var servletURL:String;





private function init():void{
userId = 12;
servletURL="http://localhost:
<http://localhost:8080/Application/topSenderServlet?TYPE=4&amp;USER_ID=>
8080/Application/topSenderServlet?TYPE=4&amp;USER_ID="+userId;
Alert.show(servletURL);
topSenders.send();
}
private function serv_result(evt:ResultEvent):void {
/* Convert XMLNode to XMLDocument. */
var xmlStr:String = evt.result.toString();
var xmlDoc:XMLDocument = new XMLDocument(xmlStr);
var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
var resultObj:Object = decoder.decodeXML(xmlDoc);
/* Assign the values... */

expenses = new ArrayCollection();
for(var i:int=0;i<resultObj.top.sender.length;i++){
Alert.show(resultObj.top.sender[i].phone);

}
}


]]>
</mx:Script>


<!--<mx:HTTPService id="topSenders" useProxy="false" resultFormat="xml"
method="POST" url="http://localhost:
<http://localhost:8080/Application/topSenderServlet?TYPE=4&amp;USER_ID=12>
8080/Application/topSenderServlet?TYPE=4&amp;USER_ID=12" 
result="serv_result(event);"/>-->

<mx:HTTPService id="topSenders" useProxy="false" resultFormat="xml"
method="POST" url="{servletURL}" 
result="serv_result(event);"/>

</mx:Application>

thanking you in advance



Reply via email to