Highlighted

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

Engaged ,
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! 

Adobe Community Professional
Correct answer by resdesign | Adobe Community Professional

It is a matter of scope.

Try to add this code:

var root = this;

Then in your function use

root.Video_Display.gotoAndStop(0);	

 

 

Views

636

Likes

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

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

Engaged ,
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! 

Adobe Community Professional
Correct answer by resdesign | Adobe Community Professional

It is a matter of scope.

Try to add this code:

var root = this;

Then in your function use

root.Video_Display.gotoAndStop(0);	

 

 

Views

637

Likes

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
Oct 07, 2019 0
Adobe Community Professional ,
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);	

 

 

Likes

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
Reply
Loading...
Oct 07, 2019 1
Engaged ,
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!

 

Likes

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
Reply
Loading...
Oct 07, 2019 0
Adobe Community Professional ,
Oct 07, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Oct 07, 2019 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Oct 07, 2019 0
Engaged ,
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

Likes

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
Reply
Loading...
Oct 07, 2019 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Oct 07, 2019 0
Engaged ,
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 +?

Likes

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
Reply
Loading...
Oct 07, 2019 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Oct 07, 2019 0
ClayUUID LATEST
Adobe Community Professional ,
Oct 07, 2019

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
Oct 07, 2019 1