TypeError: Error #1009: Cannot access a property or method of a null object reference when loading a movie in AS3

A problem I ran into today: I have an swf file that I need to load into a main file, but I kept hitting the following issue: after calling loadSwf(“xxxx.swf”), it throws TypeError: Error #1009: Cannot access a property or method of a null object reference. The loading code looks like this: private function loadMainSwf(url):void { var urlR:URLRequest=new URLRequest(url); containtLoader.unload(); containtLoader.load(urlR); containtLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,loadHandler); containtLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadCompHandler); } private function loadHandler(e:ProgressEvent):void { gLoad=e.target.bytesLoaded; gAll=e.target.bytesTotal; per=Math.floor(gLoad / gAll * 100); percent=per + “%”; perString.text=percent; } private function loadCompHandler(e:Event):void { containtLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,loadHandler); containtLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE,loadCompHandler); addChild(containtLoader); }

Flash