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

Animate CC Canvas - Cannot read property 'gotoAndPlay' of undefined?

Engaged ,
Oct 04, 2018 Oct 04, 2018

I have made a function that resets Movie Clips:

function reset_TXT(){

this.txtScroll_PF.gotoAndPlay(0);

this.txtScroll_MD.gotoAndPlay(0);

}

When a frame is accessed, the function is fired:

reset_TXT();

I get this odd error:

Frame 1? Frame 1 has no reference to this function at all!

It is Defined in Frame 2:

It is Called in Frame 2 and all subsequent frames after:

So, my function is indeed Defined, so why do I get this error, too?

Calling it this way only produces a different error:

this.reset_TXT();

Uncaught TypeError: this.reset_TXT is not a function

Can anyone explain this madness?

Thanks!

1.3K
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 , Oct 04, 2018 Oct 04, 2018

Hi.

If you console.log the 'this' keyword inside of that function you'll see that it refers to the Window object.

One way of solving this issue is to store a reference to the current timeline first. Like this:

var that = this;

function reset_TXT()

{

    that.txtScroll_PF.gotoAndStop(0);

    that.txtScroll_MD.gotoAndStop(0);

}

I hope this helps.

Regards,

JC

Translate
Community Expert ,
Oct 04, 2018 Oct 04, 2018
LATEST

Hi.

If you console.log the 'this' keyword inside of that function you'll see that it refers to the Window object.

One way of solving this issue is to store a reference to the current timeline first. Like this:

var that = this;

function reset_TXT()

{

    that.txtScroll_PF.gotoAndStop(0);

    that.txtScroll_MD.gotoAndStop(0);

}

I hope 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