Skip to main content
Participating Frequently
May 12, 2021
Question

Button inactive with randomizer, but fine without it

  • May 12, 2021
  • 2 replies
  • 170 views

Hi everyone,

 

First time poster, and I've run into a weird problem with the randomizer that I can't find the solution for 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;
	}
}

 

    This topic has been closed for replies.

    2 replies

    Liam Dilley
    Inspiring
    May 18, 2021

    This for a web page?

    If so why does the button need to be scripted and not just a html anchor?

    issashaAuthor
    Participating Frequently
    May 12, 2021

    I guess I should have noted that this is for Adobe Animate!