Button on first frame doesn't work with Math.random()
- May 12, 2021
- 1 reply
- 577 views
Hi everyone,
I've run into a weird problem in Adobe Animate with the randomizer, and I can't find the solution for it through google. I'm creating a product slideshow banner with 5 frames total. It will have previous and next buttons, and each frame will have a ClickToGoToWebPage button leading to the product's page.
The slide and buttons work great, with and without the randomizer, but I have noticed that when the page initially loads, the first frame's button to the webpage does nothing, no matter how many times I click on it. If I scroll to the next slide with the previous/next buttons, then all the buttons are fine.
It's always the button on the first slide that doesn't seem to work with the randomizer. I know it's the randomizer, because without it, the button on the first frame works as it should.
Does anyone have any tips on what I should check?
Here's my code from the first frame, and I've attached a crude screenshot, if it helps!
var nextFrame = 0
var totalFrames = 4;
this.gotoAndStop(1+Math.random()*5);
this.stop();
this.next.addEventListener("click", fl_ClickToGoToAndStopAtFrame.bind(this));
function fl_ClickToGoToAndStopAtFrame()
{
nextFrame++;
if(nextFrame > totalFrames) {
nextFrame = 0;
this.gotoAndStop(nextFrame);
}
else {
this.gotoAndStop(nextFrame);
}
}
this.previous.addEventListener("click", fl_ClickToGoToAndStopAtFrame_3.bind(this));
function fl_ClickToGoToAndStopAtFrame_3()
{
nextFrame--;
if(nextFrame < 0) {
nextFrame = totalFrames;
this.gotoAndStop(nextFrame);
}
else {
this.gotoAndStop(nextFrame);
}
}
/* Click to Go to Web Page, corrected with IF statement */
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;
}
}
