user176579
user176579

Reputation:

Flex RemoteObject Synchronous call

In the code below when I call chkAuthentication function from another function
the remoteObj.login (login function in my service file (.php)) is called after the remaining code in that function.
i.e., the loginStatus is returned from the function before the result-handler function loginResult is called. but my loginStatus is supposed to be set in loginResult function. It seems that the asynchronous behaviour is the culprit.
what should I do in order to get the loginResult function to complete first?
Please help me out. Thank you.

    private var loginStatus:Boolean;

     public function chkAuthentication(loginVOObj:LoginVO):String{
                remoteObj.login.addEventListener(ResultEvent.RESULT,loginResult);  
        remoteObj.login(loginVOObj);
        if(loginStatus == true){
            return displayName;
        }
        else{
            return 'fail';
        }
     }

     private function loginResult(result:ResultEvent):void
             {
        if(result.result == null){
            loginStatus=false;
        }else{
            loginStatus=true;

        }

     }

Upvotes: 0

Views: 1391

Answers (2)

Dan Monego
Dan Monego

Reputation: 10117

The previous answer is correct - rather than depending on the service to act synchronously, which, aside from performance issues, is a rare case in flex, you should use the loginResult function to store the login status in this object or an object that you're using to store the application's state. Then, display it using a databound control:

<mx:label text={userStatus.loginDisplay} />

Upvotes: 0

Christophe Herreman
Christophe Herreman

Reputation: 16085

The chkAuthentication method should not return a String since it is asynchronous. Instead, just create an instance variable and set its String value in the loginResult method. You can then use a binding or dispatch an event to update the UI.

Upvotes: 2

Related Questions