actionscript 3 - Error adding a movieclip that adds more movieclips to self in as3 -


package   {     import flash.display.*;      public class documentclass extends movieclip     {         public var playscreen:avoiderclass;          public function documentclass()          {             playscreen.addeventlistener(playerevent.dead, onplayerdeath);             playscreen.x = 0;             playscreen.y = 0;             playscreen = new avoiderclass();             addchild(playscreen);         }         public function onplayerdeath(playerevent:playerevent):void         {             var gameover:gameover = new gameover();             gameover.x = 0;             gameover.y = 0;             addchild(gameover);              playscreen = null;         }     }  } 

ok, worked when stage (this class) class pulled player , enemy movieclips it. added stage , made other 1 playscreen... have no idea why isn't working, give me possibilities why wouldn't, no errors pop up...

you have set variable playscreen new avoiderclass object this:

        playscreen = new avoiderclass(); 

before doing..

        playscreen.addeventlistener(playerevent.dead, onplayerdeath);         playscreen.x = 0;         playscreen.y = 0; 

please try way.

public class documentclass extends movieclip {     public var playscreen:avoiderclass;      public function documentclass(){         // construct object first         playscreen = new avoiderclass();         // manipulate it.         playscreen.addeventlistener(playerevent.dead, onplayerdeath);         playscreen.x = 0;         playscreen.y = 0;         addchild(playscreen);     } 

and here in function not forget remove playscreen displaylist

    public function onplayerdeath(playerevent:playerevent):void {         var gameover:gameover = new gameover();         gameover.x = 0;         gameover.y = 0;         addchild(gameover);         // first remove playscreen display list         removechild(playscreen);         // set null, unreachable , eligible gc         playscreen = null;     }   } } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -