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

Cannot read property 'gotoAndStop' of undefined? It is Defined.

Engaged ,
Oct 07, 2019 Oct 07, 2019

Copy link to clipboard

Copied

		function Reset_A() {
		 this.Video_Display.gotoAndStop(0);		
		};
		
		 this.Video_Display.gotoAndStop(0);

 

this.Video_Display.gotoAndStop(0); fires just fine, unless I call it from within in a function...

If I have a function in a click event that fires Reset_A(); then suddenly my Video_Display is "undefined"?

How can it be both defined and undefined?

 

Can anyone make sense of that?

 

Thanks! 

Views

1.3K

Translate

Translate

Report

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

LEGEND , Oct 07, 2019 Oct 07, 2019

It is a matter of scope.

Try to add this code:

var root = this;

Then in your function use

root.Video_Display.gotoAndStop(0);	

 

 

Votes

Translate

Translate
LEGEND ,
Oct 07, 2019 Oct 07, 2019

Copy link to clipboard

Copied

It is a matter of scope.

Try to add this code:

var root = this;

Then in your function use

root.Video_Display.gotoAndStop(0);	

 

 

Votes

Translate

Translate

Report

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
Engaged ,
Oct 07, 2019 Oct 07, 2019

Copy link to clipboard

Copied

That did work, but still does not make sense.

How would anyone have known to do that? I've never had to do that before, why would that be necessary for one function but not for others?
This seems indistinguishable from invoking magic words, instead of writing code with clear rules. 
Thank you!

 

Votes

Translate

Translate

Report

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 ,
Oct 07, 2019 Oct 07, 2019

Copy link to clipboard

Copied

Please mark as correct so it helps others when doing a search.

Votes

Translate

Translate

Report

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 ,
Oct 07, 2019 Oct 07, 2019

Copy link to clipboard

Copied

Anyway understanding scope is important espcially when dealing with functions and different timelines. I try to put all my code in frame one and use a variable for the timeline so I have an easy reference to the main timeline. BTW, you can also exportRoot fro inside a symbol.

Votes

Translate

Translate

Report

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
Engaged ,
Oct 07, 2019 Oct 07, 2019

Copy link to clipboard

Copied

How do I mark it correct? What do I click?

I am not digging this forum redesign... 

clipboard_image_0.png

Votes

Translate

Translate

Report

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 ,
Oct 07, 2019 Oct 07, 2019

Copy link to clipboard

Copied

There should be a correct Answer option under the answer. Probably click on the plus sign.

 

correctAnswer.png

Votes

Translate

Translate

Report

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
Engaged ,
Oct 07, 2019 Oct 07, 2019

Copy link to clipboard

Copied

I tried that, clicking on the teeny, tiny + button but it does nothing at all.
Typical Adobe, always 'fixing' things until they cease to work... this forum redesign is a real misfire. 
When I Reply and want to make a line break with ctrl+Enter, this forum thinks I just hit Enter!
Which submits my comment before I'm done typing, so I have to open it in editor, where the line break shortcut then works... wtf Adobe? What do you see when you hit the +?

Votes

Translate

Translate

Report

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 ,
Oct 07, 2019 Oct 07, 2019

Copy link to clipboard

Copied

and you do not have "more" either. Interesting. Well don't worry about it. I'll mark it.

Votes

Translate

Translate

Report

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 ,
Oct 07, 2019 Oct 07, 2019

Copy link to clipboard

Copied

LATEST

It's not working because you're calling the function as an event handler, and in event handlers, "this" is set to the global window object, not any Animate timeline or object.

 

You can resolve this problem by binding the event handler function to a specific scope:

 

somebutton.addEventListener("click", myHandlerFunction.bind(this));

 

(but that makes removing it a nuisance)

 

Or you can just stash the current value of "this" in a variable that's within lexical scope of the event handler:

 

var localThis = this;
function Reset_A() {
    localThis.Video_Display.gotoAndStop(0);
};

 

You can see the value of "this" change by putting alert(this); in your setup code, and again in your event handler function.

Votes

Translate

Translate

Report

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