5 Replies Latest reply on Apr 2, 2007 9:49 PM by kglad

    need help creating function

    jonblaze87
      I'm having a real tough time trying to figure out a function for a dynamic text box. What I am trying to do is have a function to
      call 2 random numbers to a dynamic text box. But the numbers would be in the form of a question(which I am guessing would have to be a string value) and then have button that would remove that question and display a new question.

      So, lets say I have this on frame 1 with a button that would generate the fuction to a dynamic text box on frame 2.

      var n1:Number = Math.floor(Math.random() * (13 - 1)) + 1;
      var n2:Number = Math.floor(Math.random() * (13 - 1)) + 1;

      I need the dynamic text box to display the numbers as a question, like this for example:
      n1 + "+" + n2 + "="
      I'm not sure how to make a function for this.

      Then a button on frame 2 would be pressed to remove the question and display a new question.
      I know I would need to call the function to generate a new question but I'm not sure what code to use
      to remove the displaying question.

      Also, how would I create a counter to keep track of how many questions are asked, that would add up to 10 questions.

      Any suggestions or advice would be very appreciated.
      Thanks

        • 1. Re: need help creating function
          kglad Adobe Community Professional & MVP
          you can call the function below anytime you want to populate the textfield passed as the first parameter with an addition question containing summands between upperLimit and lowerLimit:

          • 2. need help creating function
            jonblaze87 Level 1
            Thanks for the reply. Unfortunately I'm not really sure whats going on in this code.
            There's some things I forgot to mention. On frame 2 I have a user imput text box to anwer the question. I have a function to calc the numbers. The vars in my first post are the actual vars in my script. I'll just display my code here so you can see what I'm trying to do because I'm not sure how I would incorporate your code. One more thing, I need to use these particular vars for this project.
            Sorry I'm really new to this stuff.

            var questionsToAsk:Number = 10;
            var questionsAsked:Number = 0;
            var questionsCorrect:Number = 0;
            var n1:Number = Math.floor(Math.random() * (13 - 1)) + 1;
            var n2:Number = Math.floor(Math.random() * (13 - 1)) + 1;
            var correctAnswer:Number;
            var userAnswer:Number;

            function randRange1() {
            Math.floor(Math.random() * (13 - 1)) + 1;
            return n1;
            }
            function randRange2() {
            Math.floor(Math.random() * (13 - 1)) + 1;
            return n2;
            }

            function calcOps(n1,n2) {
            correctAnswer = n1 + n2;
            return correctAnswer;
            }

            What do you suggest I try?
            • 4. need help creating function
              jonblaze87 Level 1
              ah, this looks alot easier for me to interpret. Thank you. I will give this a try and let you know how it turned out. Thanks again :)
              • 5. Re: need help creating function
                kglad Adobe Community Professional & MVP
                you're welcome.