Your Ad Here

June 30, 2010

Random Number in Flash

Title: Random Number between a Range in Flash

Category : Intermediate
Actionscript : 2.0

Here you will learn to create a Random number in Macromedia Flash between a range.

1- Open Macromedia Flash and create a new file.

2- Select the very first frame on the timeline and open up the action script panel (Press 'F9').

3- Write the below written script in it.
stop();

var high = 1;
var low = 100;
var randNum = Math.floor(Math.random()*(high-low))+low;
trace(randNum);

4- Test the movie (Press Ctrl+Enter). Done

Description:
stop();
//Stops the movie on current Frame

var high = 1;
//A variable which holds the initial value of the range
var low = 100;
//A variable which holds the final value of the range
var randNum = Math.floor(Math.random()*(high-low))+low;
//A formula with floor function to calculate the range between the two numbers(high-low)
trace(randNum);
//Prints the result on the Output window

No comments:

Post a Comment

Please use sensible language.....!