CreateJS / Adob​​e Animate CC:测试一个简单的功能

CreateJS / Adobe Animate CC: testing a simple function

我正在尝试测试 运行 在第一帧中声明的一个简单函数。当我在 frame 50 上写 fl_DoRestart(); 时,出现以下错误:Uncaught ReferenceError: fl_DoRestart is not defined,但它是在第一帧上定义的。为什么这不起作用?这在 actionscript 中曾经非常简单:(

我最终需要能够从另一个函数调用这个函数,现在我只是在测试它。

这是我在第一个框架上的功能:

function fl_DoRestart(){
        this.gotoAndPlay(1);
        console.log("play From Start");
    }

该函数已在该框架上定义,但它没有引用任何内容。您只能从该框架脚本调用它(并且 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 导出中的帧脚本都会 运行,因此您可能需要检查是否在 运行ning 脚本之前定义了内容。

if (this.fl_DoRestart == null) {
   // Then define stuff here
}

干杯。