Call a web service that queries a SQL database and returns data to Flex
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" creationComplete="userRequest.returnRecords()"> <mx:VBox> <mx:Label text="Username" /> <mx:TextInput id="username" /> <mx:Button label="Submit" click="clickHandler()" /> <mx:DataGrid id="dgUserRequest"> <mx:columns> <mx:DataGridColumn headerText="User ID" dataField="USERID" /> <mx:DataGridColumn headerText="User Name" dataField="USERNAME" /> </mx:columns> </mx:DataGrid> </mx:VBox> <mx:WebService id="userRequest" wsdl="http://localhost/a.php?wsdl"> <mx:operation name="returnRecords" resultFormat="object" fault="mx.controls.Alert.show(event.fault.faultString)" result="remotingCFCHandler(event)" /> <mx:operation name="insertRecord" result="insertCFCHandler()" fault="mx.controls.Alert.show(event.fault.faultString)" /> </mx:WebService> <mx:Script> import mx.rpc.events.ResultEvent; private function remotingCFCHandler(e:ResultEvent):void { dgUserRequest.dataProvider = e.result; } private function insertCFCHandler():void { userRequest.returnRecords(); } private function clickHandler():void { userRequest.insertRecord(username.text); } </mx:Script> </mx:Application>