Skip to main content
Darth Mau
Participant
February 6, 2019
Answered

HTML5 and navigation buttons

  • February 6, 2019
  • 1 reply
  • 332 views

I have two mc arrows with btn inside: go back and forward that jumps to a certain frame, but I'm not getting it to work perfectly. They go back and forth, but there comes a time that everything is very slow, as if they were accumulating actions. I put this code and I do not know if there is something wrong with it. I'm still new to HTML5.

JoãoCésar​ can you help?

this.stop();

function fl_ClickToGoToAndPlayFromFrame1()

{

this.gotoAndPlay(21);

}

function fl_ClickToGoToAndPlayFromFrame2()

{

this.gotoAndPlay(13);

}

this.setaBtn.addEventListener("click", fl_ClickToGoToAndPlayFromFrame1.bind(this));

this.setaVolta.addEventListener("click", fl_ClickToGoToAndPlayFromFrame2.bind(this));

Mensagem editada por: Mauricio Costa

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

This probably happens because when you go back and forth you keep adding multiple listeners to the same object.

To avoid this, you can do something like this:

if (!this.started)

{

    this.setaBtn.addEventListener("click", fl_ClickToGoToAndPlayFromFrame1.bind(this));

    this.setaVolta.addEventListener("click", fl_ClickToGoToAndPlayFromFrame2.bind(this));

    this.started = true;

}

OR THIS:

if (!this.setaBtn.hasEventListener("click"))

    this.setaBtn.addEventListener("click", fl_ClickToGoToAndPlayFromFrame1.bind(this));

if (!this.setaVolta.hasEventListener("click"))

    this.setaVolta.addEventListener("click", fl_ClickToGoToAndPlayFromFrame2.bind(this));

Please let us know if this helps.

Regards,

JC

1 reply

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
February 6, 2019

Hi.

This probably happens because when you go back and forth you keep adding multiple listeners to the same object.

To avoid this, you can do something like this:

if (!this.started)

{

    this.setaBtn.addEventListener("click", fl_ClickToGoToAndPlayFromFrame1.bind(this));

    this.setaVolta.addEventListener("click", fl_ClickToGoToAndPlayFromFrame2.bind(this));

    this.started = true;

}

OR THIS:

if (!this.setaBtn.hasEventListener("click"))

    this.setaBtn.addEventListener("click", fl_ClickToGoToAndPlayFromFrame1.bind(this));

if (!this.setaVolta.hasEventListener("click"))

    this.setaVolta.addEventListener("click", fl_ClickToGoToAndPlayFromFrame2.bind(this));

Please let us know if this helps.

Regards,

JC

Darth Mau
Darth MauAuthor
Participant
February 6, 2019

I'm not good at HTML5 so I do not quite know how to do this fix. Would it be this:

this.stop();

function fl_ClickToGoToAndPlayFromFrame1()

{

this.gotoAndPlay(21);

}

function fl_ClickToGoToAndPlayFromFrame2()

{

this.gotoAndPlay(13);

}

if (!this.started) 

    this.setaBtn.addEventListener("click", fl_ClickToGoToAndPlayFromFrame1.bind(this)); 

    this.setaVolta.addEventListener("click", fl_ClickToGoToAndPlayFromFrame2.bind(this)); 

    this.started = true; 

}

Or something like this:

this.stop();

if (!this.setaBtn.hasEventListener("click")) 

    this.setaBtn.addEventListener("click", fl_ClickToGoToAndPlayFromFrame1.bind(this)); 

 

if (!this.setaVolta.hasEventListener("click")) 

    this.setaVolta.addEventListener("click", fl_ClickToGoToAndPlayFromFrame2.bind(this));

function fl_ClickToGoToAndPlayFromFrame1()

{

this.gotoAndPlay(36);

}

function fl_ClickToGoToAndPlayFromFrame2()

{

this.gotoAndPlay(13);

}

Or is it none of this?