How to Build a Random Number Generator in Flash

How to Build a Random Number Generator in Flash thumbnail
Flash enables you to create dynamic movies.

Adobe Flash includes the ActionScript language that enables you to create supporting code for your multimedia objects, such as a script that returns an arbitrary number when a button is pushed. ActionScript allow you to create functions based on button actions. Use the ActionScript “random” method to build your own Flash random number generator.

Instructions

    • 1

      Open your Flash source file in Flash.

    • 2

      Type the text “000” using the text tool. This text block will be used to display the random number.

    • 3

      Type a value, such as “rnum” into the Variable field of the Properties panel. The text “Var:” displays next to this field.

    • 4

      Type button text, for instance, “generate a number” and press “F8.” Choose the “Movie clip” type radio and press “OK.” Type an Instance Name. For this example, use “gButton.”

    • 5

      Press “F9” to open the Actions window and insert the following:

      gButton.onRelease = function(){
      r=random(100);
      rnum = r;
      }

      The random value of “100” instructs the method to generate a number no greater than 100.

    • 6

      Press “Ctrl” and “Enter” to test your project. When the “generate a number” button is pressed, a random number displays in the text field you created.

Related Searches:

Resources

  • Photo Credit Hemera Technologies/Photos.com/Getty Images

Comments

Related Ads

Featured