all groups > flash actionscript > january 2004 >
You're in the

flash actionscript

group:

Using Math.random to go to random frames


Using Math.random to go to random frames Glen Gummess
1/23/2004 9:34:53 PM
flash actionscript:
Hello everyone. My cerebral density is preventing me from seeing the solution to this problem.

I have the following code which causes the user to jump to various frames in a timeline at random; the user clicks a component-button that actuates the addOn function below:

generateNew = function () {
n = Math.round(Math.random()*10);
};
addOn = function () {
generateNew();
gotoAndStop(n);
if (_currentFrame == n){
trace("the current frame is " + _currentFrame);
}
}
stop();

However, I don't want the user to go to the same frame twice during the session (before the page is reloaded). Can you suggest how I may prevent the same frame from recurring?

Many thanks,

Glen Gummess
Instructional Designer
University of St. Francis.
Joliet, IL

Re: Using Math.random to go to random frames elemental .std
1/23/2004 9:57:27 PM
just when random function generate a frame number save it to a variable and when you call again the random function compare it with this variable if they are equal call again random function compare again and again until the new number which is produced is different.

your script will look likes:

totalFrames=20;
frames = new Array(totalFrames);

newFrame = function () {
_root.frameN = random(totalFrames-1);
};

function check() {
for (i=1;i<=totalFrames;i++) {
if (frames == 'visited') {
_root.check = false;
} else {
frames = 'visited';
_root.check=true;
}
}
}

addOn = function () {
//i am not sure for the syntax of this loop
while (_root.check != true) {
newFrame;
}
gotoAndStop(_root.frameN+1);
}

addOn;
stop();

Do you agee ?




Re: Using Math.random to go to random frames Glen Gummess
1/23/2004 10:26:21 PM
I'll give it a try.

Thank you!

Glen

AddThis Social Bookmark Button