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
evaluates to
There is no
thisin 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
Or implement a singleton pattern to kinda get a “static class, that dispatches events”.
Singleton with event management.