actionscript 3 - Avoid null object reference errors in code inside the child SWF -


i'm creating global loader loads different swfs.
don't have access child swfs code.
i'm trying avoid null object reference errors in code inside child swf may reference "stage" etc.
i've added possible event listeners, added try/catch, tried applicationdomains , loadercontexts permutations. example:

applicationdomain = new applicationdomain(applicationdomain.currentdomain); var con:loadercontext = new loadercontext(false, applicationdomain ); con.allowcodeimport = true; var _loader:loader = new loader(); _loader.contentloaderinfo.addeventlistener(event.complete, onload); _loader.load( new urlrequest(filename + ".swf"), con); 

i can't catch error or disable/remove code such swf.
example, following main class:

package  {      import flash.display.movieclip;      public class main extends movieclip {             public function main() {             var h = this.stage.stageheight;             trace(h);         }     } } 

will crush swf try load part of swf.

typeerror: error #1009: cannot access property or method of null object reference.
@ main()

any catching error, disabling/removing code or other idea appreciated.
thanks.

do have access code in child swf files? if so, can this:

package  {      import flash.display.movieclip;      public class main extends movieclip {             public function main() {             if (stage) {                 init();             }             else {                 addeventlistener(event.added_to_stage, init);             }          }          public function init(evt:event = null):void {             removeeventlistener(event.added_to_stage, init);              // can access stage here         }     } } 

this hold off initializing child object until stage reference set. child objects constructor called first before stage set, can't rely on being there in constructor.


Comments