First, you can use a single HTTPService instance.  The AsyncToken allows you to 
match a call with a result.  Thus you only need a single result handler.  I 
assign a string value to a queryId property on the call token, then use a 
switch statement in the result handler to decide what to do next.  The code 
snippets below show an example of this.

Tracy

Sample code using HTTPService, e4x, handler function to populate a list item.  
Also shows usage of AsyncToken.

The DataGrid tag:
<mx:DataGrid id="dg" dataProvider="{_xlcMyListData}" .../>


The HTTPService tag:
<mx:HTTPService id="service" resultFormat="e4x" result="onResult(event)" 
fault="..../>

Script block declaration:
import mx.rpc.Events.ResultEvent;
import mx.rpc.AsyncToken;


[Bindable]private var _xlcMyListData:XMLListCollection;

Invoke send:
var oRequest:Object = new Object();
oRequest.Arg1 = "value1";
var callToken:AsyncToken = service.send(oRequest);
callToken.callId = "myQuery1";

Result Handler function:
private function onResult(oEvent:ResultEvent):void  {
  var xmlResult:XML = XML(event.result);                //converts result 
Object to XML. can also use "as" operator
  var xlMyListData:XMLList = xmlResult.myListData;      //depends on xml 
format, is row data
  _xlcMyListData = new XMLListCollection(xlMyListData); //wrap the XMLList in a 
collection
  trace(_xlcMyListData.toXMLString());                  //so you can see 
exactly how to specify dataField or build labelFunction
  var callToken:AsyncToken = oEvent.token;
  var sCallId = callToken.callId;                       //"myQuery1"
  switch(sCallId)  {                                    //Process the result 
conditionally
    case "myQuery1":
      doQuery2();                                       //do whatever. this 
example calls another data service query
      break;
    ... 
  }
}//onResult

________________________________________
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Harry 
Saputra
Sent: Wednesday, January 23, 2008 2:46 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Refreshing DataGrid Automatically when submit a record ( 
use two HTTPService )

Dear All,
 
I try to build simple insert and showing data with two HTTPService like that ( 
sorry for long source code ) :
 
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; xmlns="*" 
creationComplete="anggotaRetrieve.send(); createListener();" layout="absolute">
 
<mx:Script>
                <![CDATA[
                
                                import flash.events.MouseEvent;
                                                
                                
public function createListener():void {
                                
btnSubmit.addEventListener(MouseEvent.CLICK,refresh);
                                }
        
                                 public function refresh(e:MouseEvent):void {
                                anggotaRetrieve.send();
                                 }             
                                
                ]]>
</mx:Script>
 
<mx:HTTPService id="anggotaInsert" url="insert.php" useProxy="false"  
method="POST" >
                <mx:request xmlns="">
                                <username>{txtUserName.text}</username>
                                <password>{txtPassword.text}</password>
                                <email>{txtEmail.text}</email>
                </mx:request>
</mx:HTTPService>
 
<mx:HTTPService id="anggotaRetrieve" url="retrieve.php" useProxy="false">
</mx:HTTPService>
 
<mx:Form width="400" height="150" left="10" top="10">
                <mx:FormItem label="Username">
                                <mx:TextInput id="txtUserName" />
                </mx:FormItem>
                <mx:FormItem label="password">
                                <mx:TextInput id="txtPassword" />
                </mx:FormItem>
                <mx:FormItem label="Email">
                                <mx:TextInput id="txtEmail" />
                </mx:FormItem>
                <mx:FormItem label="">
                                <mx:Button id="btnSubmit" label="submit" 
click="anggotaInsert.send()" />
                </mx:FormItem>
</mx:Form>
                <mx:Panel x="10" y="168" width="500" height="250" 
layout="absolute" title="Tabel Anggota - POSTGRESQL">
                                <mx:DataGrid id="DgAnggotaRetrieve" 
dataProvider="{anggotaRetrieve.lastResult.anggota.row}" width="100%" 
height="170">
                                <mx:columns>
                                                <mx:DataGridColumn 
headerText="username" dataField="username" />
                                                <mx:DataGridColumn 
headerText="password" dataField="password" />
                                                <mx:DataGridColumn 
headerText="email" dataField="email" />
                                </mx:columns>
                                </mx:DataGrid>               
                                </mx:Panel>
</mx:Application>
 
It's Working Done, but need to click a btnSubmit twice to shown an update data 
on DataGrid.... 
How to create "just one click" and I can get a result on DataGrid ?
 
I have try to build with one HTTPService, and it's working. But I can't build 
with two HTTPService.. Help me to solving this problem.
 
Thanks for attention
 
 
 

Reply via email to