昨天做一个绘图class,做成文档类可以,直接在时间轴裏写var myClass:ClassA=new Class();就是不行。FLASH 报出“type error 1009-無法存取Null 物件參考的屬性或方法”。查了一下,class裏引用了Stage的属性,而Stage在没有被添加到displayObject之前,是Null的,这样就报错了。
需要用到这个事件来触发:Event.ADDED_TO_STAGE,调用函数init()。
if (stage) {
init();
} else {
addEventListener(Event.ADDED_TO_STAGE, init);
}
}
public function init(e:Event=null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
trace("init"+stage);
......
Event.ADDED_TO_STAGE only gets dispatched once an object has been added to a displayList, and also all its parents have been added. If it is already there, it won't fire again.
需要用到这个事件来触发:Event.ADDED_TO_STAGE,调用函数init()。
if (stage) {
init();
} else {
addEventListener(Event.ADDED_TO_STAGE, init);
}
}
public function init(e:Event=null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
trace("init"+stage);
......
Event.ADDED_TO_STAGE only gets dispatched once an object has been added to a displayList, and also all its parents have been added. If it is already there, it won't fire again.