3 Replies Latest reply on Nov 21, 2012 2:51 PM by GameHermit

    Random Number Button to Fill in 4 Fields


      Hi Everyone! Thanks to this great forum I have learned a TON and have almost completed my project!


      I am creating a fillable character sheet for a fantasy role-playing game.


      Currently, I have 4 fields that a player can type numbers into. These fields are STRRoll, DEXRoll, LOGRoll & WILRoll. These four values are used in several different calculations throughout the sheet...and works great! The game's author asked if I could also put a Random Roll Button that would generate random values for the four fields. Basically, if the player doesn't have dice handy he can still create a character.


      I was given the below function which generates the random number range that the authors want for the values. The problem is that I do not know how to attach this to a button so that  when clicked, the button generates four random values, one for each of the above fields.


      The fields should be blank when the sheet is loaded so that the player is given the option to type his numbers in or use the random roll button. It would be really cool to have the button hidden and become visible if a check box is selected...but I don't know how hard that would be to accomplish.


      Below is the function that I was given by the author...sorry but this is a bit above my understanding at this point (BUT...I'm learning!!!):


      function randomAbilityScore() {

      return Math.floor(Math.random()*10) + Math.floor(Math.random()*10) + Math.floor(Math.random()*10) + Math.floor(Math.random()*10) + Math.floor(Math.random()*10) + 35;




      Thanks for looking at tthis with me



        • 1. Re: Random Number Button to Fill in 4 Fields
          try67 MVP & Adobe Community Professional

          I'm not sure that function is correct, but if we assume that it does, you can use this code as the button's MouseUp action to use it and apply the value it returns for your fields:


          this.getField("STRRoll").value = randomAbilityScore();

          this.getField("DEXRoll").value = randomAbilityScore();

          this.getField("LOGRoll").value = randomAbilityScore();

          this.getField("WILRoll").value = randomAbilityScore();


          To show/hide a button when a check-box is ticked, place this code as the check-box's MouseUp event (replace "ShowHideButton" and "MyButton" with the actual names of the fields):


          this.getField("MyButton").display = this.getField("ShowHideButton").value=="Off" ? display.hidden : display.visible;

          • 2. Re: Random Number Button to Fill in 4 Fields
            GameHermit Level 1

            Thank you so much...I really REALLY appreciate the help! LOL...it doesn't look that difficult after seeing the code you supplied....but knowing where to start is key. I'll give this a go and let you know how it works out .

            • 3. Re: Random Number Button to Fill in 4 Fields
              GameHermit Level 1

              It worked perfectly...thank you so much for all of your help !