In my document class named Engine, the stage variable is for some reason null:
package game
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
public class Engine extends MovieClip
{
public function Engine()
{
trace(stage); // gives Null
}
}
}
This was working fine up until now. I just recently added two dynamic text fields into a symbol, and all of a sudden the stage is null. I really don't see the connection.
This is my first time using actionscript and flash, so am a bit confused at everything.
Ok, I have reproduced what you have been experiencing, by adding a TLF font to the stage in CS5, that must be what's causing it. But this code should solve your problem :
public function Engine():void
{
if( !this.stage )
this.addEventListener( Event.ADDED_TO_STAGE, init );
else
init();
}
private function init(e:Event = null):void
{
this.removeEventListener( Event.ADDED_TO_STAGE, init );
trace(stage);
}
My guess is that there is some delay in creating the stage in this case. I've had this happen and didn't know why, so this was the way I handled it. It works! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With