我有一个程序,我为舞台创建了一个单例类,所以我可以在其他类中访问它。Flash AS3 TLF文本(无法访问空对象引用的属性或方法。)
我有一些其他的文字在其中的符号,所以需要在代码中修改文本。
我的问题是,每当我使用TLF文本,而不是经典文本,我的任何类的引用的单台班获得“TypeError: Error #1009: Cannot access a property or method of a null object reference."
我以前有过这很好地工作TLF文本程序,但是这是我第一次使用舞台的单身类,所以我的猜测是这涉及到,不知何故。
我已经尝试了一些解决方案,在其他职位我见过的相关问题(如发布设置),但迄今没有已运作
下面是发生第一个错误的地方:
// Constructor
public function Zoom(object:MovieClip) {
// Set the stage
stage = StageManager.instance.stage;
// Set the zoom object
zoomObject = object;
// Add event listener for the mouse wheel
stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseZoom); // ERROR OCCURS HERE
if (Controls.instance.controls.zoomInBtn && Controls.instance.controls.zoomOutBtn) {
Controls.instance.controls.zoomInBtn.addEventListener(MouseEvent.CLICK, zoomIn);
Controls.instance.controls.zoomOutBtn.addEventListener(MouseEvent.CLICK, zoomOut);
}
}
这里是单例类:
package {
import flash.display.Stage;
// Singleton class so any other classes can access the stage.
public class StageManager {
// Publicly accessible singleton instance
public static var instance:StageManager = new StageManager();
private var m_stage:Stage;
// Getters and Setters
public function set stage(stg:Stage):void {
m_stage = stg;
}
public function get stage():Stage {
return m_stage;
}
}
}
这将有助于分享(代码的相关部分)。 – poepje
我添加了代码,但我不确定它是否真的有帮助。 – Sean
我没有看到任何与文本相关的代码?如果TLF文本是问题,那就是我们想看到的。附:你有没有调试过,以确保问题真的发生在函数的调用? – poepje