Copy link to clipboard
Copied
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:
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!
Copy link to clipboard
Copied
Hi.
I have a suggestion. Please see if this works for you:
var root = this;
root.main = function()
{
root.stop();
root.gotoAndStop(Math.floor(Math.random() * root.totalFrames));
root.previous.on("click", root.navigate, root, false, { offset: -1 });
root.next.on("click", root.navigate, root, false, { offset: 1 });
};
root.navigate = function(e, data)
{
var destination = root.currentFrame + data.offset;
root.gotoAndStop(destination > -1 ? destination : root.totalFrames -1);
};
if (!root.started)
{
root.main();
root.started = true;
}
Regards,
JC