Error #1009 - Only when added as child? *Urgent*

Ok, heres the problem… I have my game which works perfect, then when I try to use my loader… This happens.

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at buggyWars_fla::MainTimeline/buggyWars_fla::frame1()

Why would my loader be causing errors in my game swf? Btw, this is testing locally.

My Loader:


stop();
var Version = root.loaderInfo.parameters.Version;
//var request:URLRequest = new URLRequest("buggyWars.swf?" + Version);
var request:URLRequest = new URLRequest("buggyWars.swf");
var gameLoader:Loader = new Loader();
gameLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
gameLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
function loadProgress(event:ProgressEvent):void {
    var Percent:Number = event.bytesLoaded / event.bytesTotal;
    Percent = Math.round(Percent * 100);
    loadingBox.loadingText.text = "Loading... " + Percent + "%";
}
function loadComplete(e:Event):void {
    this.removeChild(loadingBox);
    this.addChild(gameLoader);
}
gameLoader.load(request);

:thumb:

Awesome! I just spent an hour turning 719 lines of timeline code into a Document class.

It works! Sweet…

I should clarify - the important part is making sure nothing runs until the ADDED_TO_FRAME event - but welcome to the world of classes! That’s excellent. :beam:

I got that. :slight_smile: All of my game elements were classes… Projectiles, etc…

I am not sure why I had my main script on the Timeline. Easier to reach I guess. :confused: