收到错误类型1061:通过静态类型的引用调用可能未定义的方法的addEventListener [英] Getting error Type 1061: Call to a possibly undefined method addEventListener through a reference with static type
本文介绍了收到错误类型1061:通过静态类型的引用调用可能未定义的方法的addEventListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我把从我的应用我的code到一个单独的AS类文件,现在我得到了以下错误:
1061:通过静态类型类引用调用可能未定义的方法的addEventListener。
1180:调用可能未定义的方法的addEventListener。
包管理器{
进口对象类型:flash.events.Event;
进口flash.events.EventDispatcher使用;
公共类RemoteManager扩展EventDispatcher {
公共职能RemoteManager(){
}
公共静态函数的init(clearCache:布尔= FALSE):无效{
的addEventListener(SETTINGS_CHANGE,settingChangeHandler);
的addEventListener(ITEMS_UPDATED,itemsUpdatedHandler);
}
}
}
解决方案
您code
的addEventListener(SETTINGS_CHANGE,settingChangeHandler);
的计算结果为
this.addEventListener(SETTINGS_CHANGE,settingChangeHandler);
没有这
的静态方法,因为它的设计没有一个实例运行。此外,你不能从一个静态类附加一个事件侦听器,并调度事件。
要么改变你的函数声明为
公共职能的init(clearCache:布尔=假):无效
或实现一个单例模式来还挺获得的静态类,即调度事件的。
I moved my code from my Application to a separate AS class file and now I'm getting the following errors:
1061: Call to a possibly undefined method addEventListener through a reference with static type Class.
1180: Call to a possibly undefined method addEventListener.
.
package managers {
import flash.events.Event;
import flash.events.EventDispatcher;
public class RemoteManager extends EventDispatcher {
public function RemoteManager() {
}
public static function init(clearCache:Boolean = false):void {
addEventListener(SETTINGS_CHANGE, settingChangeHandler);
addEventListener(ITEMS_UPDATED, itemsUpdatedHandler);
}
}
}
解决方案
Your code
addEventListener(SETTINGS_CHANGE, settingChangeHandler);
evaluates to
this.addEventListener(SETTINGS_CHANGE, settingChangeHandler);
There is no this
in a static method, since it's designed to function without an instance. Furthermore, you cannot attach an event listener and dispatch events from a static class.
Either change your function declaration to
public function init(clearCache:Boolean = false):void
Or implement a singleton pattern to kinda get a "static class, that dispatches events".
Singleton with event management.
这篇关于收到错误类型1061:通过静态类型的引用调用可能未定义的方法的addEventListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文