Learn Flash: Generate Random Numbers

Home • Members Tutorials Forum iSnapChat Contact Us 

 


Flash Tutorials

   

Flash Tutorial - Generating Random Numbers

 

Free Flash Tutorial


Step 3    <<   Previous      Intro   1   2   3   4   5     Next   >>      

 

Step Three: Setting Up the Button ActionScript

  1. If the Button Library is closed, open it: Window > Common Libraries > Buttons
  2. Go through the folder and select a button. I selected: Classic Buttons > Circle Buttons > Next
  3. Note: If you take a button from the Common Button Library avoid Knobs, Faders and Component buttons as they work differently.

  4. Drag a button on to the: Main Stage
  5. If the Actions Panel is closed, open it: Window > Action (F9)
  6. Important Note: In the top left corner of the Actions Panel it must say: Actions - Button

    If it does not say Actions - Button it can be for two reasons:

  7. If Script Assist is on, Switch it off:
  8. Note: With Script Assist on you cannot type in the Actions Panel. If you want to learn more about Script Assist see the tutorial on the Actions Panel

  9. Type (or copy and paste) the following code in the Actions Panel;
  10. on (release) {
       myDisplay = random (10) +1;
    }

  11. Test your Movie: Control > Test Movie (Ctrl Enter)


The ActionScript Explained:

on (release) {
When the user releases the Mouse button what is between the curly braces ...


myDisplay = random (10) +1;
In this case the random function creates a random number that starts at 0 and ends on the 10th digit. Which is the number specified in the parentheses: (10). If you start your count from zero (instead of 1) then the 10th digit is 9 (not 10)! So to make it count form 1 to 10 I simply add one to the result. Hence the +1.

}
The curly brace ends the on (release) statement.

         

Step 3    <<   Previous      Intro   1   2   3   4   5     Next   >>      


29180 visitors to this page since 2 July 07 •

Phil Schulz's Facebook Profile
Webwasp is Phil Schulz's baby. You are welcome to contact me or become my Facebook friend: Click here

 Top of Page HomeMembers Tutorials Forum iSnapChat Contact Us 
 All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.