13 Replies Latest reply on Nov 29, 2012 9:40 PM by kglad

    loopVars

    Ron Colmen Level 2

      I'm not sure if the logic here is best. But how can I make SECTION B loop over and over untill th if condition fails? is it possible to have 'ReceiveLoad2' inside a loop?

       

      var numF:Number = 1;

      var numC:Number = 0;

      var ReceiveLoad2:LoadVars = new LoadVars();

      goNext_btn.onRelease = function () {

                numC = (numF-numF);

                for (i=0; i<30; i++) {

                          if (_root.radioStage_mc["radioBtn"+i].textA.text != _root.radioStage_mc["radioBtn"+i].textB.text and numC < 1){

                                              numC++;

                          SenderLoad.codeID = _root.radioStage_mc["radioBtn"+i].idNum.text;

                          SenderLoad.item = _root.radioStage_mc["radioBtn"+i].newCode.text;

                          _root.radioStage_mc["radioBtn"+i].updateS.text = "yes";

                          SenderLoad.sendAndLoad("http://www.web.com/D.php",ReceiveLoad2,"POST");

                          }

                }

      }

      ////SECTION B

      ReceiveLoad2.onLoad = function () {

                if (ReceiveLoad2.dat== "successful"){

                          for (i=0; i<30; i++) {

                          if (_root.radioStage_mc["radioBtn"+i].textA.text != _root.radioStage_mc["radioBtn"+i].textB.text and _root.radioStage_mc["radioBtn"+i].updateS.text == "" and numC < (numC + numF) and numC < 30){

                                    numC++;

                                    SenderLoad.codeID = _root.radioStage_mc["radioBtn"+i].idNum.text;

                          SenderLoad.item = _root.radioStage_mc["radioBtn"+i].newCode.text;

       

                          _root.radioStage_mc["radioBtn"+i].updateS.text = "yes";

                          SenderLoad.sendAndLoad("http://www.web.com/D.php",ReceiveLoad2,"POST"); //Here the ReceiveLoad2 repeats ONCE only. How can I make it loop over and over untill th if condition fails? is it possible to have 'ReceiveLoad2' inside a loop?

                          }

                }

       

      }

        • 1. Re: loopVars
          kglad Adobe Community Professional & MVP

          this:

           

             if (_root.radioStage_mc["radioBtn"+i].textA.text != _root.radioStage_mc["radioBtn"+i].textB.text and numC < 1){

           

          and should be:

           

             if (_root.radioStage_mc["radioBtn"+i].textA.text != _root.radioStage_mc["radioBtn"+i].textB.text && numC < 1){

           

          though that code sniippet doesn't make sense.  you will only loop from i=0 to i=0.

           

          so, what are you trying to do with that first code snippet?

           

          section B also makes no sense.  what is that if-statement supposed to check?

          1 person found this helpful
          • 2. Re: loopVars
            Ron Colmen Level 2

            Thank you Kglad.

             

            In the first snippet, I want to get a start and then when the ReceiveLoad2 is been received I wanted to loop it 30 times.

            Also I've used the if statement in the first snippet to check only the first updated record and pass the rest to be handeled by SECTION B.

             

            SECTION B

            Only the updated records will be required to be sent via ReceiveLoad2. So I've used the If statement to check only the onces which were updated (textA.text != textB.text /// condition ture - data was updated) && to stop the loop after numC reashes 30

            • 3. Re: loopVars
              kglad Adobe Community Professional & MVP

              i understand why you might want to only updated changed data but what's the point of waiting until something is received from D.php when nothing is used from that return?

              • 4. Re: loopVars
                Ron Colmen Level 2

                Good point and I agree.

                 

                I was thinking of using it to display a confirmation.

                i.e.  "17 records updated" //so I know for sure all 17 was updated.

                • 5. Re: loopVars
                  kglad Adobe Community Professional & MVP

                  so,  use:

                   

                   

                  var ReceiveLoad2:LoadVars = new LoadVars();

                  var SendLoad:LoadVars = new LoadVars();

                   

                  ReceiveLoad2.onLoad = function () {

                  // have your php return the number of updated items and do something with that although that number is known when the data are sent (updateItemNum)

                  }

                   

                  goNext_btn.onRelease = function () {

                            var updateItemNum:Number = 0;

                            for (i=0; i<30; i++) {

                                      if (_root.radioStage_mc["radioBtn"+i].textA.text != _root.radioStage_mc["radioBtn"+i].textB.text ){

                                           SenderLoad["codeID_"+updateItemNum] = _root.radioStage_mc["radioBtn"+i].idNum.text;

                                           SenderLoad["item_"+updateItemNum] = _root.radioStage_mc["radioBtn"+i].newCode.text;

                                           _root.radioStage_mc["radioBtn"+i].updateS.text = "yes";

                                           updateItemNum++;

                                      }

                            }

                       if(updateItemNum>0){

                            // the number of updated items is updateItemNum;

                            SenderLoad.sendAndLoad("http://www.web.com/D.php",ReceiveLoad2,"POST");

                       }

                  }

                  1 person found this helpful
                  • 6. Re: loopVars
                    Ron Colmen Level 2

                      foreach ($_POST as $key => $value) {

                       $$key = $value;

                    }

                    $query = "UPDATE db1 SET item=$key WHERE Code =$value";

                    $result= mysql_query($query);

                     

                    I'm not familier with foreach(). Can you help me out here?

                    • 7. Re: loopVars
                      kglad Adobe Community Professional & MVP

                       

                       

                        foreach ($_POST as $key => $value) {

                         $$key = $value;

                      }

                      $query = "UPDATE db1 SET ";

                      for($i=0;$i<30;$i++){

                      if(isset(${"codeID_".$i})){

                      $query .= "item='" .${'item_'.$i}."' WHERE Code ='".${'codeID_'.$i}.'",";  //<- note: there are single and double quotes

                      }

                      }

                      $query = substr($query, 0, -2);

                      $result= mysql_query($query);

                       

                       

                      • 8. Re: loopVars
                        Ron Colmen Level 2

                        Thank you Kglad. I'll going to try it now.

                        • 9. Re: loopVars
                          kglad Adobe Community Professional & MVP

                          you're welcome.

                          • 10. Re: loopVars
                            Ron Colmen Level 2

                            For certain resons I will have to stick with this code and get it to loop 30 times. Are you able to give me a solution to make SECTION B loop untill the IF conditions fails? At the meoment SECTION A sends the data once (correct) and SECTION B sends the first record only (wrong - need to repeat 28 times more). I'm gussing that's because ReceiveLoad2 also needs to be within a loop?

                             

                             

                            ////SECTION A

                            var numF:Number = 1;

                            var numC:Number = 0;

                            var ReceiveLoad2:LoadVars = new LoadVars();

                            goNext_btn.onRelease = function () {

                                      numC = (numF-numF);

                                      for (i=0; i<30; i++) {

                                                if (_root.radioStage_mc["radioBtn"+i].textA.text != _root.radioStage_mc["radioBtn"+i].textB.text && numC < 1){

                                                                    numC++;

                                                SenderLoad.codeID = _root.radioStage_mc["radioBtn"+i].idNum.text;

                                                SenderLoad.item = _root.radioStage_mc["radioBtn"+i].newCode.text;

                                                _root.radioStage_mc["radioBtn"+i].updateS.text = "yes";

                                                SenderLoad.sendAndLoad("http://www.web.com/D.php",ReceiveLoad2,"POST");

                                                }

                                      }

                            }

                            ////SECTION B

                            ReceiveLoad2.onLoad = function () {

                                      if (ReceiveLoad2.dat== "successful"){

                                                for (i=0; i<30; i++) {

                                                if (_root.radioStage_mc["radioBtn"+i].textA.text != _root.radioStage_mc["radioBtn"+i].textB.text and _root.radioStage_mc["radioBtn"+i].updateS.text == "" && numC < (numC + numF) && numC < 30){

                                                          numC++;

                                                          SenderLoad.codeID = _root.radioStage_mc["radioBtn"+i].idNum.text;

                                                SenderLoad.item = _root.radioStage_mc["radioBtn"+i].newCode.text;

                             

                                                _root.radioStage_mc["radioBtn"+i].updateS.text = "yes";

                                                SenderLoad.sendAndLoad("http://www.web.com/D.php",ReceiveLoad2,"POST"); //Here the ReceiveLoad2 repeats ONCE only. How can I make it loop over and over untill th if condition fails? is it possible to have 'ReceiveLoad2' inside a loop?

                                                }

                                      }

                             

                            }

                            • 11. Re: loopVars
                              kglad Adobe Community Professional & MVP

                              ////SECTION B

                              ReceiveLoad2.onLoad = function () {

                                        if (ReceiveLoad2.dat== "successful"){

                                                  for (i=0; i<30; i++) {

                                                  if (_root.radioStage_mc["radioBtn"+i].textA.text != _root.radioStage_mc["radioBtn"+i].textB.text and _root.radioStage_mc["radioBtn"+i].updateS.text == "" && numC < (numC + numF) && numC < 30){

                                                            numC++;

                                                            SenderLoad.codeID = _root.radioStage_mc["radioBtn"+i].idNum.text;

                                                  SenderLoad.item = _root.radioStage_mc["radioBtn"+i].newCode.text;

                               

                                                  _root.radioStage_mc["radioBtn"+i].updateS.text = "yes";

                              } else {

                                                  SenderLoad.sendAndLoad("http://www.web.com/D.php",ReceiveLoad2,"POST");

                              break;

                                                  }

                                        }

                               

                              }

                              1 person found this helpful
                              • 12. Re: loopVars
                                Ron Colmen Level 2

                                Thanks Kglad.

                                • 13. Re: loopVars
                                  kglad Adobe Community Professional & MVP

                                  you're welcome.