I'm trying to test run a simple function that's declared in the first frame. When I write fl_DoRestart();
on frame 50
I get the following error: Uncaught ReferenceError: fl_DoRestart is not defined
, but it's defined on frame one. Why's this not working? This used to be very simple in actionscript :(
I eventually need to be able to call this function from another function, right now I'm just testing it.
Here's my function on frame one:
function fl_DoRestart(){
this.gotoAndPlay(1);
console.log("play From Start");
}
答案 0 :(得分:1)
该功能已在该框架上定义,但它没有任何参考。您只能从该框架脚本调用它(而this
可能是window
而不是该脚本)
使用Animate导出时,建议在this
上存储方法调用,以便可以访问它们。
this.fl_DoRestart(){
this.gotoAndPlay(1);
console.log("play From Start");
}
this.fl_DoRestart();
// From the root
exportRoot.someMoveClip.fl_DoRestart();
// Using a callback
btn.addEventListener("click", someMovieClip.fl_DoRestart.bind(this));
// Shortcut with "on()"
btn.on("click", someMovieClip.fl_DoRestart, this);
希望能够说明这是如何运作的。还需要考虑的另一件事是Animate CC导出中的帧脚本将在每次访问该帧时运行,因此您可能需要在运行脚本之前检查是否已定义事物。
if (this.fl_DoRestart == null) {
// Then define stuff here
}
干杯。