Turning off Math.random() after one use?
Hi, I currently have a 5 product banner with a randomizer and next/previous buttons. When it launches, it loads one of those frames using the Math.random() command. However, it does it again when either of the next & previous buttons are clicked. Is there any way for me to turn that off after it's been executed once at launch?
For example:
- HTML randomly loads a frame from 1 to 5 (E.g. Frame 3).
I'd like the next button to continue in sequential order from there: 3, 4, 5, 1, 2, 3
- HTML randomly loads Frame 4.
The next button continues sequetionally when clicked: 4,5,1,2,3,4
Here's what I have in Frame 0:
var nextFrame = 1;
var totalFrames = 5;
var randomFrame = Math.random()*5;
var lastPicked = randomFrame - 1;
this.next.addEventListener("click", fl_ClickToGoToAndStopAtFrame.bind(this));
function fl_ClickToGoToAndStopAtFrame()
{
nextFrame++;
if (nextFrame > totalFrames) {
nextFrame = 1;
}
this.gotoAndStop(nextFrame);
}
this.previous.addEventListener("click", fl_ClickToGoToAndStopAtFrame.bind(this));
function fl_ClickToGoToAndStopAtFrame()
{
nextFrame--;
if(nextFrame < 1) {
nextFrame = totalFrames;
}
this.gotoAndStop(nextFrame);
}
this.gotoAndPlay(randomFrame);
{
if (randomFrame == currentFrame){
randomFrame = lastPicked;
}
}
And on Frame 1 (the first product), I have this:
this.stop();
/* Product 1 Link */
this.product1_cta.addEventListener("click", fl_ClickToGoToWebPage);
function fl_ClickToGoToWebPage() {
window.open("https://www.google.com", "_blank");
if(!this.started) {
this.product1_cta.addEventListener("click", fl_ClickToGoToWebPage);
this.started = true;
}
}
I'm still learning, so sorry if this isn't right. I'm using the code snippet and action wizard to adjust as I need to.
Thank you!
