我需要一个由 Animate CC 通过以下方式连接到外部文件来访问的函数:Global>Includes。
然后,当我单击影片剪辑时,我需要运行外部文件上的函数。
例如,我的影片剪辑上的代码是:
this.stop(); // stops the action on my movie clip
myFunction(); // trying to access function from external javascipt file
外部文件中的代码是:
function myFunction() { // this code is not being called from my movie clip
alert("working!");
}
控制台日志指出:“myFunction”未定义。
感谢您的帮助,
克里斯汀
最佳答案
如果您试图达到全局范围(我认为您是这样),这意味着您希望将此函数放置在一个关键帧上并从不同的关键帧或图层触发它。像这样重新编写代码:
--- write these things this way for local ---
var foo = bar;
var count = 0;
function foobar(){
// do stuff;
}
foobar();
count++;
--- write these things this way for global ---
foo = bar;
count = 0;
foobar = function(){
// do stuff;
}
foobar();
count++;
关于javascript - 动画 CC : Creating/accessing global function from external . js 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48154017/