[flexcoders] Re: how to call dynamic servlet
Hi All , Sorry for the late reply , i have been told to send the working code for me and here is it below , it might be complicated but this is what i have right now , Thanks Tracy Spratt tspr...@... nts333rd for your advise , i welcome ur suggest i ll try to test ur way , what i need is to get the elements returned by the xml from the servlet one by one and the below code did that but anyhow i ll test your way ... thanking all ... here is the current working code ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.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; import mx.rpc.http.HTTPService; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; [Bindable] public var expenses:ArrayCollection; public var userId:int; public var servletURL:String; public var topSenders:HTTPService; private function init():void{ userId = 12; useHttpService(); } public function useHttpService():void { topSenders = new HTTPService(); topSenders.url = http://localhost:8080/Application/topSenderServlet?USER_ID=+userId.toString(); topSenders.method = POST; topSenders.addEventListener(result, resultHandler); topSenders.addEventListener(fault, faultHandler); topSenders.useProxy=false; topSenders.resultFormat=e4x; topSenders.send(); topSenders.disconnect(); topSenders.clearResult(true); topSenders = null; topSenders.logout(); } public function resultHandler(event:ResultEvent):void { trace(resultHandler invoked); var xmlStr:String = event.result.toString(); var xmlDoc:XMLDocument = new XMLDocument(xmlStr); var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true); var resultObj:Object = decoder.decodeXML(xmlDoc); for(var i:int=0;iresultObj.linkinscreen.topsenders.sender.length;i++){ Alert.show(resultObj.topsenders.sender[i].phone); } } public function faultHandler(event:FaultEvent):void { trace(faultHandler Invoked); Alert.show('Oops there is a problem!' + event.fault.message); } ]] /mx:Script /mx:Application
[flexcoders] Re: how to call dynamic servlet
Hi , Thanks alot for the help, I have made some modification and it is working now , i ll post the full mxml file later for the sharing Thanking all of you ..
RE: [flexcoders] Re: how to call dynamic servlet
Why are you converting the e4x XML into the legacy XMLDocument? And if you really are satisfied working with dynamic Object instead of XML, then use resultFormat=object and skip all that decdoing stuff. Flex will do that for you. But that is the worst of both worlds; you lose the power of e4x and suffer the diminished access performance of a dynamic object. I suggest you use XML and XMLListCollection instead. _ From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of anitha2324 Sent: Sunday, March 08, 2009 3:20 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: how to call dynamic servlet Hi Thanks alot for your reply, I have removed the binding variables, replaced xml by e4x , and setted the url before the service.send but am still unable to get the successful result here is my modified code ?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; public var userId:int; public var servletURL:String; private function init():void{ userId = 12; servletURL=http://localhost: http://localhost:8080/Application/topSenderServlet?TYPE=4amp;USER_ID= 8080/Application/topSenderServlet?TYPE=4amp;USER_ID=+userId; Alert.show(servletURL); topSenders.url=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;iresultObj.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=4amp;USER_ID=12 8080/Application/topSenderServlet?TYPE=4amp;USER_ID=12 result=serv_result(event);/-- mx:HTTPService id=topSenders useProxy=false resultFormat=e4x method=POST result=serv_result(event);/ /mx:Application thanking you in Advance
[flexcoders] Re: how to call dynamic servlet
Hi Thanks alot for your reply, I have removed the binding variables, replaced xml by e4x , and setted the url before the service.send but am still unable to get the successful result here is my modified code ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.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; public var userId:int; public var servletURL:String; private function init():void{ userId = 12; servletURL=http://localhost:8080/Application/topSenderServlet?TYPE=4amp;USER_ID=+userId; Alert.show(servletURL); topSenders.url=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;iresultObj.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:8080/Application/topSenderServlet?TYPE=4amp;USER_ID=12; result=serv_result(event);/-- mx:HTTPService id=topSenders useProxy=false resultFormat=e4x method=POST result=serv_result(event);/ /mx:Application thanking you in Advance