5 Replies Latest reply on Oct 22, 2006 9:50 AM by leotemp

    RemoteObject sequence of event

    World_Traveler
      Hello !

      I have a function that makes a call to a RemoteService (to check record duplicates) but it seems that my function does not wait for the call to return (or the RemoteObject result handler to complete) before moving on with the rest of the function's code.

      I will see the record insert itself in the datagrid and THEN I will see the Alert I have placed in my result handler telling me that this record should not be inserted.....

      Is there a way for me to code something for the function to wait for the RemoteObject call to complete and return its result before moving on with the function's code ?.

      Thanks

      Steve

        • 1. Re: RemoteObject sequence of event
          leotemp Level 1
          create a function that activates the remoteObject in the manner you wish, then create a sepperate function to handle the result. In the RemoteObject set "result="{nameOfFunction()}" or create an event listener for it if your not using MXML. EXAMPLE:

          <remoteObject id="objRO" result="{parseRObject()}>

          callRObject() {
          // --- RO calls or what have you go here--//
          // option event listener if you dont want to use MXML //
          objRO.addEventListener("result", parseRObject);
          }
          parseRObject() {
          // your code for handling the result //
          }

          This is crude but your should get the idea, basically you want to tell the app to wait for the "result" event before doing anything else, in this case calling the "parseRObject" function.
          • 2. Re: RemoteObject sequence of event
            World_Traveler Level 1
            Thanks Leo,

            I already implemented you suggestion in my code but it did not help.

            I've read that all RemoteObject calls are asynchronous. The resultEvent will get triggered when the result is returned to the application, it could take seconds if the database server is busy. Meanwhile the actionscript will continue to execute. The code is not blocked

            Example (

            public function checkDuplicate():void
            {
            // Service has a resultHandler defined elsewhere
            myService.cfCheckDuplicate();
            }

            public function checkAuthorization():void
            {
            // Service has a resultHandler defined elsewhere
            myService.cfCheckAuthorization();
            }

            public function checkAvailability():void
            {
            // Service has a resultHandler defined elsewhere
            myService.cfcheckAvailability();
            }

            public function insertRecord():void
            {
            checkDuplicate() as Boolean;
            checkAuthorization() as Boolean;
            checkAvailability() as Boolean;

            // dup is a bound variable populated in the checkDuplicate resultHandler;
            // auth is a bound variable populated in the checkAuthorization resultHandler;
            // avail is a bound variable populated in the checkAvailability resultHandler;

            // HOW CAN I WAIT HERE FOR ALL 3 RESULT HANDLERS TO BE READY ?

            if (dup == false || auth == true || avail == true)
            {
            performRecordInsert();
            }
            else
            {
            Alert.show("Record cannot be inserted");
            }

            }

            Right now the record will be inserted or not depending on the state of the last result in the RemoteObject objects (the new results are not bounded yet)....

            At some point the resultHandlers will be executed but it is too late to reject the record...

            Steve
            • 3. Re: RemoteObject sequence of event
              leotemp Level 1
              Im not sure why the EventListener cant be used, maybe im confused but cant you do your RemoteObject checks in sequence, each triggered by the lasts "result" event and then on your last RemoteObject check result execute your insert record function?
              • 4. Re: RemoteObject sequence of event
                World_Traveler Level 1
                Leo,

                I may have misunderstood the "objRO.addEventListener("result", parseRObject);" part. I did not realize that there was more flexibility in registering the event listener that way instead of doing it in MXML. I thought it was the exact same thing and I used MXML instead....

                I will test that approach and if it does indeed solve my problem I will tag your solution as the answer.

                Thanks Leo.
                • 5. Re: RemoteObject sequence of event
                  leotemp Level 1
                  whatever i just want to make sure you get your answer, The hard core flex guys seems to be absent latley. Its good policy to mark closed threads with the answer just to make it easy on the rest of us trying to help, this forum isnt exactly convient to use and tracking down people that need help can be hard :(