Is null in a document class? ActionScript 3.0 Flash CS5

In my document class called Engine, the stage variable is null for some reason:

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 has worked so far. I recently added two dynamic text fields to a character, and suddenly the stage was zero. I really don't see the connection.

This is my first time using actioncript and flash, so I'm a little confused about everything.

+3
source share
2 answers

Well, I reproduced what you experienced by adding a TLF font to the scene in CS5, which should be the reason for this. 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);
 }  

, . , , , . !:)

+6

, . .

( ) , FLA, TLF TextField. , , .

. . , , - Event.REMOVED_FROM_STAGE .

FLA , TLF TextField ( ) , FLA AS2, AS3. , TLF TextField ( ) . .

, : / TLF, , ?

0

All Articles