Developing Webs logo
Google
Web DW-Main DW-Photoshop
Visit the message board for solutions or post a question Check out the Classes offered for free at Developing Webs Voice Chat submit a tutorial, resources, article, font for publication consideration and earn a one way link back to your site Get more specifics about the Developing Webs Voice chat room and its room members View the current news at Developing Webs alternative sites which are resources for your d3evelopment needs Join Developing Webs Chat Link to us on your web page to help support this resource! Check out Developing Webs At yahoo groups! Developing Webs Home Adobe Photoshop Tutorials Macromedia Flash Tutorials Jasc Paint Shop Pro Tutorials Adobe Illustrator Animation basics Some Basic PHP tutorials Perl Tutorials HTML Tutorials Cascading Style Sheets javascript Front Page Tutorials Macromedia Dream Weaver Tutorials dreamweaver Publishing your site, FTP, ChMod, Promotions Tools to help you create your site Free and shareware fonts to download Photographs to use in your projects Shop for your site needs Free Online classes REcommend this site to others Log in or edit your information when logged in Developingwebs Log Out Change My Account details and preferences
RSS Newsfeed
for your site
DW News
Calendar
DW Forum
Right click on button and copy shortcut

Add to My Yahoo!

Reminder
Remember to book mark this site!



Request a Tutorial

Generating Random Numbers

To demonstrate random numbers, we can use the Math.random action script. We can simply make a 60 frame movie that loops and generates a new random number with each loop. 60 frames will loop every 5 seconds at 12 frames per second (12 frames per second X 5 seconds = 60 frames.) We will set a variable equal to the random number, and display the variable in a text box, thereby demonstrating the new random number every 5 seconds.

1. Open a new document. Rename Layer 1 Text.

2. Select your type tool and click on your stage. Set your text box to

  • dymanic
  • Single line
  • Black
  • Align left
  • var = randomnumber  (no spaces)
  • Type in 6 -8 figures aligned left. The actual type is not important except to use to size the box.

3. Click in frame 60 and hit your F5 key to extend your key frame to 60 frames long.
 

4. Click the icon on the bottom of the timeline to insert a layer. The layer should appear above the text layer. Name this layer actions.

5. Click in frame 1 of your actions layer and hit your F7 key to insert a blank keyframe.

6. Click back in frame 1 of the actions layer. Open your actions panel.

7. From the actions toolbox on the left, click Actions=> Variables=> Set Variable

8. For the variable, type in randomnumber exactly the way you did it for the var value in the text box. There should be no spaces.

9. Click your cursor in the value box. Then from the actions toolbox on the left, select Objects=> Core=> Math=> Methods=> Random. You will need to check the box for Expression so that flash will evaluate the script for Value. Now your script now looks like this: 

randomnumber = Math.random();
 

10. Test your movie. You will see a random number generated every 5 seconds. Notice that the random number is between 0 and 1. This is always what this script produces.

The Next tutorial will show you how to expand the generated number to limits other then 0 to 1.



"Building The Web Into a Nicer Place -- One Site At A Time"
Developing Webs Group Copyright © 2001-2010 All Rights Reserved
Privacy and Legal