Preloader problem

I’m a little new to as3 but find it alot of fun and challenging. I’m currently creating a website for someone I know in flash (cs4).
I ve completed the entire front end of the site but to give it a polished look I started to add a preloader.

I’m adding the preloader on the first frame of the .fla file and the actual website starts from frame 5. The site plays fine by itself without the preloader. when i add the preloader set of codes i get the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at web_as3_fla::MainTimeline/frame5()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at web_as3_fla::clap_mc_28()

I understand that now the problem is probably with the main movie but I fail to understand then y it played properly without the preloader! ;(

this is my preloader code:

this.addEventListener(Event.ENTER_FRAME, loading);
function loading(e:Event):void{
var total:Number = this.stage.loaderInfo.bytesTotal;
var loaded:Number = this.stage.loaderInfo.bytesLoaded;
loadBar.scaleX = loaded/total;
loadText.text = Math.floor((loaded/total)*100)+ “%”;
if (total == loaded){
this.removeEventListener(Event.ENTER_FRAME, loading);

Now how to I find what is wrong and then how do I correct it?
Please help!
Thanks :slight_smile: