Skip to main content
jeffery wright
Inspiring
October 4, 2018
Answered

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

  • October 4, 2018
  • 1 reply
  • 1399 views

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!

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

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

1 reply

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
October 4, 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