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!
It is a matter of scope.
Try to add this code:
var root = this;
Then in your function use
root.Video_Display.gotoAndStop(0);
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);
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!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
How do I mark it correct? What do I click?
I am not digging this forum redesign...
Copy link to clipboard
Copied
There should be a correct Answer option under the answer. Probably click on the plus sign.
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 +?
Copy link to clipboard
Copied
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.