Custom Preloader

Hi guys/gals,

Here’s my dilemma:

I’m trying to make a simple custom preloader in flash 9 and I’m very new to as3. The basic thing i need is a MC that has 100 frames and a dynamic text box that displays the percentage.

here’s my code:

//–Event Handler–\
addEventListener(Event.ENTER_FRAME, loading);

//-- My Function–\
function loading(e:Event) {
var bytestotal = stage.loaderInfo.bytesTotal;
var bytesloaded = stage.loaderInfo.bytesLoaded;
var percent = Math.round(bytesloaded * 100/bytestotal);

//–loader_mc is my movie clip that has 100 frames–\
loader_mc.gotoAndPlay(percent);

//–percent_txt is the text box name of the percent i want to display–\
percent_txt.text=int(percent)+"%";

if (bytesloaded >= bytestotal) {

	gotoAndStop(2);
	removeEventListener(Event.ENTER_FRAME, loading);
	removeChild(loader_mc);
}

}
stop();


for some reason it’s not working and i get an error:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display: displayObjectContainer/removeChild()
at PreloaderTest_fla::MainTimeline/loading()

Any help would be much appreciated!

Thanks again,
mrmeir