Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

HTML5 and navigation buttons

New Here ,
Feb 06, 2019 Feb 06, 2019

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

302
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 06, 2019 Feb 06, 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_ClickToGoToAndPlayFrom

...
Translate
Community Expert ,
Feb 06, 2019 Feb 06, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 06, 2019 Feb 06, 2019
LATEST

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines