Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now