0

Responder オブジェクトから値を返す必要があります。今、私は持っています:

private function pro():int {
    gateway.connect('http://10.0.2.2:5000/gateway');
    var id:int = 0;
    function ret_pr(result:*):int {
       return result
    }
    var responder:Responder = new Responder(ret_pr);
    gateway.call('sx.xj', responder);
    return id
}

基本的に、ret_pr の戻り値を id またはその関数から返されるものに取得する方法を知る必要があります。レスポンダーはそれを食べているようです。これは一度に複数回実行されるため、パブリック変数を他の場所で使用することはできません。そのため、ローカル スコープが必要です。

4

2 に答える 2

2

これは、AMF サーバーへの接続を作成し、それを呼び出して、結果の値を保存する方法です。結果はすぐには得られないので、サーバーから返されたデータに「応答」するようにレスポンダーを設定します。

public function init():void
{
    connection = new NetConnection();
    connection.connect('http://10.0.2.2:5000/gateway');
    setSessionID( 1 );
}
public function setSessionID(user_id:String):void
{
    var amfResponder:Responder = new Responder(setSessionIDResult, onFault);
    connection.call("ServerService.setSessionID", amfResponder , user_id);
}

private function setSessionIDResult(result:Object):void {
    id = result.id;
    // here you'd do something to notify that the data has been downloaded. I'll usually 
    // use a custom Event class that just notifies that the data is ready,but I'd store 
    // it here in the class with the AMF call to keep all my data in one place.
}
private function onFault(fault:Object):void {
    trace("AMFPHP error: "+fault);
}

それがあなたを正しい方向に向けることができることを願っています。

于 2009-11-12T22:48:51.820 に答える
0
private function pro():int {
    gateway.connect('http://10.0.2.2:5000/gateway');
    var id:int = 0;
    function ret_pr(result:*):int {
       return result
    }
    var responder:Responder = new Responder(ret_pr);
    gateway.call('sx.xj', responder);
    return id
}

このコードは、あなたが望むものを得ることは決してありません。適切な結果関数を使用する必要があります。無名関数レスポンダの戻り値は、周囲の関数によって使用されません。この場合、常に 0 を返します。ここでは非同期呼び出しを扱っており、それに応じてロジックでそれを処理する必要があります。

private function pro():void {
    gateway.connect('http://10.0.2.2:5000/gateway');
    var responder:Responder = new Responder(handleResponse);
    gateway.call('sx.xj', responder);
} 

private function handleResponse(result:*):void
{
    var event:MyCustomNotificationEvent = new MyCustomNotificationEvent( 
            MyCustomNotificationEvent.RESULTS_RECEIVED, result);
    dispatchEvent(event);
    //a listener responds to this and does work on your result
    //or maybe here you add the result to an array, or some other 
    //mechanism
}

anon関数/クロージャーを使用しているという点は、ある種の疑似同期動作を提供することにはなりません。

于 2009-11-12T23:02:36.793 に答える