Passing parameters to an HTTPService
The followig example shows how you can pass parameters to an HTTPService by passing an Object in the HTTPService’s send()
method. The remote ColdFusion script is a simple “hello world” type script which accepts a single parameter, “name”, and returns a single parameter, “welcomeMessage”.
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.ValidationResultEvent; import mx.utils.StringUtil; private function submit_click(evt:MouseEvent):void { var result:ValidationResultEvent = stringValidator.validate(); var params:Object = {}; lbl.text = ""; switch (result.type) { case ValidationResultEvent.INVALID: Alert.show(result.message, result.type); break; case ValidationResultEvent.VALID: params["name"] = StringUtil.trim(firstName.text); httpServ.send(params); break; } } ]]> </mx:Script> <mx:StringValidator id="stringValidator" source="{firstName}" property="text" minLength="2" maxLength="{firstName.maxChars}" /> <mx:HTTPService id="httpServ"> <mx:resultFormat>flashvars</mx:resultFormat> <mx:url>http://www.flash-mx.com/mm/greeting.cfm</mx:url> <mx:result>lbl.text = httpServ.lastResult.welcomeMessage;</mx:result> <mx:fault>Alert.show(event.toString(), event.type);</mx:fault> </mx:HTTPService> <mx:ApplicationControlBar dock="true"> <mx:Form> <mx:FormItem label="Name:" required="true" direction="horizontal"> <mx:TextInput id="firstName" maxChars="20" /> <mx:Button label="Submit" click="submit_click(event);" /> </mx:FormItem> </mx:Form> </mx:ApplicationControlBar> <mx:Label id="lbl" fontSize="32" /> </mx:Application> |
9:50 AM
|
Labels:
Flex HTTPService,
Flex Samples
|
This entry was posted on 9:50 AM
and is filed under
Flex HTTPService
,
Flex Samples
.
You can follow any responses to this entry through
the RSS 2.0 feed.
You can leave a response,
or trackback from your own site.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment