Uh bit fustrated here, I'm trying to make a basic preloader for my main swf.
All it does is loads the swf whilst tracking its progress, then adding childen and what not.
The code for the preloader is:
var Request:URLRequest = new URLRequest("Space Defender.swf");
var L:Loader = new Loader();
L.load(Request);
L.contentLoaderInfo.addEventListener(Event.OPEN,showPreloader);
L.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress);
L.contentLoaderInfo.addEventListener(Event.COMPLETE,showContent);
var bar:loadingBar = new loadingBar();
function showPreloader(event:Event):void {
addChild(bar);
bar.x = stage.stageWidth/2;
bar.y = stage.stageHeight/2;
}
function showProgress(event:ProgressEvent):void {
var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
bar.width = 200 * percentLoaded;
}
function showContent(event:Event):void {
removeChild(bar);
L.x = 0;
L.y = 0;
addChild(L);
}
When I compile however I get a runtimer error after loading:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Main()[C:\Flash Project\Space Defender\Main.as:32]
Line 31-33:
Main.stage=root.stage;
stage.addEventListener(KeyboardEvent.KEY_DOWN, menu.keyIn);
stage.addChild(menu);
I commented lines 32-33 out and it worked fine. Unfortunately with out the menu I can't actually physically start the game...
The stage is referenced at line 31 in main so that I can use it in my other classes, but I believe that's where the problem lies.
Does anyone know how to solve this?