Viral videos from Unruly Media

Unruly Media creates viral campaigns for the world's top brands. The video is then distributed worldwide via Unruly Media's ad distribution network. See some of the videos here:

 








Flash Random Number Generator

view all »


In this tutorial I am going to show you how to create a basic random number generator using Actionscript 2.

Your final result will look something like this - just click the button to generate a random number from 1-100:

STEP 1

First off, open a new actionscript 2 file. Rename layer 1 to ’stuff’ and create a new layer called ‘actions’ and lock it. On the ’stuff’ layer, select the text tool and draw a text box on the stage. Open your properties panel (usually situated at the bottom of your screen) and set the text box property to ‘Dynamic Text’.

Flash Random Number Generator

Give this textbox an instance name of ‘textDisplay’.

Flash Random Number Generator

STEP 2

Now we need to create a button on the stage to activate the number generator. We will just create a basic button by drawing a square on the stage and typing ‘Generate’ on it, pressing f8 and convert to a button called ‘BTN_generate’. (For a more in depth tutorial on buttons, please click here). Give this button an instance name of ‘BTN_generate’. Your stage should now look like this:

Flash Random Number Generator

STEP 3

Now for adding the actionscript. On your actions layer, press f9 to open the actions panel and place the following code:

BTN_generate.onRelease = function(){
textDisplay = random (100) +1;
}

The first line of code states that when the button (’BTN_generate’) is released, operate the function…
The next line is the function. This tells ‘textDisplay’ to show a random number from 0-100, but the + 1 will prevent us from getting a 0.
Hit CTRL + enter and click the generate button, and here you have a basic random number generator.

The Dude

Did this tutorial help you? If so, click the bookmark button, stumble me, add me to your twitter and tell your friends! Alternatively, sign up and leave a comment!

Not what you were looking for? Then leave a comment or email me and we’ll get you the tutorials you need.

Vote in HexoSearch Help me out by voting for this tutorial

Did this post help you? If so help us continue to grow and Digg this page or Share on Twitter!

If you haven't already, sign up to our RSS feed or register to recieve updates direct to your email!

8 Responses to “Flash Random Number Generator”


  1. [...] more from the original source:  Flash Random Number Generator | FREE flash tutorials | The Dude [...]


  2. Pretty basic but very good for beginners!


  3. Thats the idea :p

  4. mark

    I’m trying to use a generator several times (15) like you do here but I don’t want the same number generated twice within the 15 generations.

  5. Huy

    very good. although it is basic, suitable for beginner

  6. Robert

    hi there I was wondering could you replace the number with a list of words? I am using it to learn a language and I want to generate a word from a list that I put in so that i can make random sentences. I am a total noob at it so was wondering how to go about doing this. Thanks guys.

    Tutorial was awesome!

  7. Jeuk

    Hi good tutorial.

    i need to make a word generator.
    can someone please help me?


  8. Hai, i used the code tat u sent and it has no syntax errors and the number is not displayed.. what might be the problm..??i use ac2 and flash8. plez suggest

Leave a Reply