0
我從精靈繼承單個類,以便它可以訪問舞臺,這樣的..舞臺什麼時候開始初始化?
package
{
import flash.display.Sprite;
public class C extends Sprite
{
private var _grid:Array = new Array();
public function get Grid():Array
{
return _grid;
}
private static var _instance:C;
public static function get Instance():C
{
if (_instance == null)
{
_instance = new C();
}
return _instance;
}
function C()
{
this.InitGrid();
}
private function InitGrid():void
{
var gridWidth:Number = stage.width/10;
}
}
}
這引發錯誤
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at C/InitGrid()
at C()
at C$/get Instance()
at C()
at Main()
如果我有一個int代替stage.width代碼執行OK。 是因爲這個對象還沒有被添加到stage的任何孩子的displayList中?
謝謝