2 Replies Latest reply on Apr 26, 2006 11:51 AM by gitman1234

    Random Text Answers Possible?

    gitman1234
      I have two text fields. One for user input, who types a yes or no question(contents irrelevant) and then hits a button which then would randomly bring up one of 50 different answers in a dynamic text box. Then a button to clear the fields to start over. If anyone can point me in the right direction, I sure would appreciate it. Many thanks in advance.
        • 1. Re: Random Text Answers Possible?
          sneakyimp Level 2
          put your answers in an array:

          var myArray:Array = new Array();
          myArray[0] = 'Definitely Not';
          myArray[1] = 'signs point to yes';
          myArray[2] = 'Of Course!';
          .
          .
          .
          etc.

          then pick one at random:

          var someNum:Number;
          someNum = Math.floor(Math.random() * myArray.length);
          if (someNum == myArray.length) {
          // this will probably never happen...but just in case!
          someNum = myArray.length - 1;
          }
          var myAnswer:String = myArray[someNum];
          trace(myAnswer);then to pick one at random:
          • 2. Re: Random Text Answers Possible?
            gitman1234 Level 1
            Thank you...new to actionscripting and feel overwhelmed. Do I attach this script to
            user_txt or answer_txt field. Any ideas on the reset button? Again thank you so much.