5 Replies Latest reply on Dec 7, 2006 7:36 AM by kglad

    Pausing Loops


      any help i could get with this would be much appreciated.

      I am just wanting to know how do you momentarily stop a loop.

      ie, i am doing a questionnaire but i want to store all questions and answers as as either arrays or objects, not 100% sure of this yet. i will make this decision when i find out how to pause loops.

      Basically i want to loop through every question in teh array or object and i want the loop to pause when each question has been asked.. when the question has been answered by the user i want the loop to automatically restart again by looping to the next question in the object or array.

      Is this at all possible??

      The reason for this is because i dont want to make a huge if statement which ends up making about 500 lines of code.

      Please help if you can. Any slight idea would be much appreciated.

      the style of array i would use would be along the lines of.

      var questions:Array = ["question 1?","question 2?","question 3?","question 4?","question 5?","question 6?"];

      and the code i would use for the number of loops would be

      for (i=0; i<=questions.length; i++)

      or i would use a 'while' equivalent of this.

      thats the kind of lines im thinking along, i will take any ideas.


        • 1. Re: Pausing Loops
          kglad Adobe Community Professional & MVP
          it is possible, but because you can't easily pause a for-loop or while loop (you have to break out and break back in when ready), it's easier to use some other kind of loop.

          you'll need some way for the user to indicate that the answer to the current question is complete. you'll then increment questions index and display that question etc.
          • 2. Re: Pausing Loops
            leewilson86 Level 1
            thanks for the reply,

            breaking out and then back in was what i initially thought and then i was going to have an increment on an onRelease function of the answer which the user clicks, which increments the loop count by 1, ie goto the next question,

            i tried doign this but i either got an infinate loop or my application kept looping all frames in my movie, even though there was no command telling the movie to skip frame and the current frame i am in has a stop(); command attached to it.

            is there another type of loop that can do this?? like a FOR EACH loop or something like that? so for each time the answer is clicked loop??

            is this possible and if so would someone be able to provide me with a working demo or something???


            • 3. Re: Pausing Loops
              kglad Adobe Community Professional & MVP
              no, read my 2nd paragraph. you don't the kind of loop you're considering.

              you just need to progress through your questions array as the user indicates the current question has been answered. incrementing the questions index will cause the current question to advance to the next question in your questions array.

              i you have some code showing how a user will indicate a question has been answered i'll show you how to code for the above.
              • 4. Re: Pausing Loops
                leewilson86 Level 1
                Hello thanks for your reply. I had another read through what you said about using break and its actually really easy when you think about it. This is what i done and it works fine. Just need to tweak it to adopt a multi choice questionnaire now :-D

                var i:Number = 0;
                var question:Number = 1;
                var questions:Array = ["", "1.", "2.","3.", "4.", "5.", "6.", "7.", "8.", "9.", "10."];
                function showQuestion() {
                if (question<=questions.length) { // makes sure user does not face undefined field when all questions are answered
                for (i=question; i<=questions.length; ) { // show questions
                question_txt.text = questions[question]; // show question
                question += 1; // increment question number
                break; // leave loop and wait for user to answer
                next_btn.onRelease = function() {
                showQuestion(); // show next question

                Thanks a lot again for your helps

                • 5. Re: Pausing Loops
                  kglad Adobe Community Professional & MVP
                  you're welcome. but as i said, the following is even easier: