4 Replies Latest reply on May 31, 2007 10:13 AM by SUNITAR

    Flex Function

    SUNITAR
      Hi,

      I have these 2 public functions. I want to call the function2 only when the function1 is successful. Is there any way I can tell
      to run the 2nd function when the first function is successful or finished. Please help. Thanks in advance. I am a newbee..
        • 1. Re: Flex Function
          peterent Level 2
          If you make your first function return a Boolean - true or false - you can use it in an if-statement and the run function2 if the first function returns true:

          public function f1() : Boolean
          {
          // do whatever and
          return true;
          // or
          return false;
          }

          Then: if( f1() ) f2();
          • 2. Re: Flex Function
            SUNITAR Level 1
            Thanks so much for your reply. The first function inserts data into a sql server table thru remote object. And this insert function
            runs inside a for loop. Like for (var i:int = 0; i < myData.length; i++ ) {


            var newProduct:Product = myData ;

            myService.insertsp( newProduct ) ;
            }//end for loop

            As you said then I am telling it to return true and want to call another function when all the insert is done. But before even all the insert is done its calling the second function. Is there any way I can fix it ? Please help..
            • 3. Re: Flex Function
              BLXWebMaster Level 1
              How about just setting a variable for the myData.length. Then on your Result myService increment the variable by 1 and check if it equals myData.length. If so, fire your second function.
              • 4. Re: Flex Function
                SUNITAR Level 1
                Thanks a lot BLXWebMaster !! This one worked !!
                Thanks for your help..