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

Creating/accessing global function from external .js file

New Here ,
Jan 08, 2018 Jan 08, 2018

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

233
Translate
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 ,
Jan 08, 2018 Jan 08, 2018

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?

Translate
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
New Here ,
Jan 08, 2018 Jan 08, 2018

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....

Translate
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 ,
Jan 08, 2018 Jan 08, 2018
LATEST

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?

Translate
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