【发布时间】:2011-12-10 11:45:38
【问题描述】:
我迷路了。当我的文档类第一次尝试访问舞台上的简单文本字段(从 IDE 添加,而不是 actionscript)时,我收到了 TypeError: Error #1009: Cannot access a property or method of a null object reference. 输出消息
package {
import flash.display.*;
import fl.text.*;
import flash.text.*;
import flash.events.*;
import flash.net.*;
public class Main extends MovieClip {
private var _netConnection:NetConnection;
private var _responder:Responder;
/* some other public + private vars */
public function Main() {
init();
}
public function init(e:*=null):void {
_netConnection = new NetConnection();
_responder = new Responder(uponResult);
txt.text = "init()";
}
/* more functions */
}
}
我尝试添加 txt.addEventListener(Event.ENTER_FRAME, init); 以防 txt TLFTextField 在开始时不...那里...,但它仍然输出错误。
我觉得自己有点像个白痴atm,预后文件是什么? JB
【问题讨论】:
-
这取决于您初始化
txt的方式和位置。你能发布代码吗? -
txt 是通过 Flash IDE 手动添加到舞台的,而不是通过 actionscript。
-
如果 txt 不存在,您也无法为其添加事件侦听器...您是否尝试过在文档类的 Event.ADDED_TO_STAGE 上调用 init?
-
我现在做到了,谢谢 weltraumpirat 和 heartcode :)
标签: actionscript-3 flash-cs5 typeerror document-class