Copy link to clipboard
Copied
Hi,
I need to have a function that is accessed by Animate CC through connecting to an external file by: Global>Includes.
Then I need to run the function that is sitting on the external file when I click on a movie clip.
For example, the code on my movie clip is:
this.stop(); // stops the action on my movie clip
myFunction(); // trying to access function from external javascipt file
The code in the external file is:
function myFunction() { // this code is not being called from my movie clip
alert("working!");
}
The console log states: "myFunction" is undefined.
Thanks for the help,
Kristen
Copy link to clipboard
Copied
ristenk82 wrote
The console log states: "myFunction" is undefined.
You should probably believe what the console says. Have you verified that your external code library is in fact loading? Checked the browser console for errors? Stuck an alert() statement in the external library to make sure it's getting loaded?
Copy link to clipboard
Copied
No, that is not it. The .js file is linked correctly because I have an alert in it to see if it runs just when the Animate index file is first opened and it does. The problem is that I am not calling the function correctly but I don't know the correct way to call it or to make the function global for it to be called. I'm not sure if I'm suppose to put something in front of myFunction(); in the movie clip to make it look for a function outside of itself....
Copy link to clipboard
Copied
If you're defining it as a global function, you don't have to prefix the function call with anything.
It's often the case that a function call will fail if the function is called before it's been declared, but that shouldn't be happening here since you're using Animate itself to attach the JS file.
What is the first line of the function declaration in the JS file?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now