I have the following two classes:
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
var test:NewClass = new NewClass();
}
}
}
AND
package
{
import flash.display.Sprite;
public class NewClass extends Sprite
{
public function NewClass()
{
trace(stage.width);
}
}
}
I get the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference. at NewClass()[C:\Documents and Settings\Roma\poo\src\NewClass.as:10] at Main/init()[C:\Documents and Settings\Roma\poo\src\Main.as:23] at Main()[C:\Documents and Settings\Roma\poo\src\Main.as:15]
Why???