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

removeEventListener in another timeline frame for html canvas

Explorer ,
Jun 18, 2018 Jun 18, 2018

Hi!

I really do not know the advice. I work with Adobe Animate canvas. I need to turn on the eventlistener inside the movieclip in frame 2 of its timeline, and turn it off in frame 3 of its timeline. On frame 3 I go through the canvas button. But the removeeventlistener works only in the frame where the listener was defined.

In frame 2 I have this code:

aliasRozne = Rozne.bind (this);

this.addEventListener ("tick", aliasRozne);

function Rozne ()

{

     frame = frame + 1

     if (frame == 50)

     {

          this.svetlo1.visible = true;

     }

     if (frame == 250)

     {

          this.svetlo5.visible = true;

          this.removeEventListener ("tick", aliasRozne);

     }

}

In frame 3 I have this code:

this.removeEventListener ("tick", aliasRozne);

But the listener does not turn off in frame 3 and frame is still increasing. When I stay on frame 2, everything is ok.

Do you have any advice?

Thanks!

569
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 , Jun 18, 2018 Jun 18, 2018

use:

user

this.aliasRozne = Rozne.bind (this);

this.addEventListener ("tick", this.aliasRozne);

function Rozne ()

{

     frame = frame + 1

     if (frame == 50)

     {

          this.svetlo1.visible = true;

     }

     if (frame == 250)

     {

          this.svetlo5.visible = true;

          this.removeEventListener ("tick", this.aliasRozne);

     }

}

In frame 3 I have this code:

this.removeEventListener ("tick", this.aliasRozne);

Translate
Community Expert ,
Jun 18, 2018 Jun 18, 2018

use:

user

this.aliasRozne = Rozne.bind (this);

this.addEventListener ("tick", this.aliasRozne);

function Rozne ()

{

     frame = frame + 1

     if (frame == 50)

     {

          this.svetlo1.visible = true;

     }

     if (frame == 250)

     {

          this.svetlo5.visible = true;

          this.removeEventListener ("tick", this.aliasRozne);

     }

}

In frame 3 I have this code:

this.removeEventListener ("tick", this.aliasRozne);

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
Explorer ,
Jun 18, 2018 Jun 18, 2018

thanks! its right!

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
LEGEND ,
Jun 18, 2018 Jun 18, 2018

You really should be using this.frame instead of just frame, which creates a global variable. And I hope you're initializing it, because adding 1 to undefined isn't pretty.

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
Explorer ,
Jun 18, 2018 Jun 18, 2018

yes, thank you

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
LEGEND ,
Jun 18, 2018 Jun 18, 2018

I am Spartacus.

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
Community Expert ,
Jun 18, 2018 Jun 18, 2018
LATEST

I am Spartacus.

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
Community Expert ,
Jun 18, 2018 Jun 18, 2018

you're welcome.

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