# Preloader Problem with AS3 Document classes

**URL:** https://forum.kirupa.com/t/preloader-problem-with-as3-document-classes/265664
**Category:** flash
**Created:** [July 11, 2008, 4:17am UTC](https://forum.kirupa.com/t/preloader-problem-with-as3-document-classes/265664 "2008-07-11T04:17:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![weno42](https://avatars.discourse-cdn.com/v4/letter/w/74df32/32.png) [@weno42](https://forum.kirupa.com/u/weno42)
#### Post date: [July 11, 2008, 4:17am UTC](https://forum.kirupa.com/t/preloader-problem-with-as3-document-classes/265664/1 "2008-07-11T04:17:01Z")

</div>

Hi, a friend and I have been working for months on a Flash/AS3 video game, and we’re stumped on one issue, the preloader. We need to either preload the game, which uses all document class as files, either within the timeline of the main swf, or into another swf. We’ve tried both options and we always get a 1009 Error, accessing a null class.

I thought this post would fix the problem:

> **[ActionScript 3 Tip of the Day - Page 15](https://www.kirupa.com/forum/showthread.php?223798-ActionScript-3-Tip-of-the-Day&s=8f9aea3f49123945ec0791501b63cacf&p=1952513#post1952513)**
>
> Got a web design/development question or just want to hang out with the most awesome people on the planet? Drop on in!

But I can’t get it to work. I can’t figure out how to add the main class to the display list, and have everything reference the stage.

Has anyone run into this problem?  
Any suggestions?

The preloader we want is quite simple:

package code {

public class Preloader extends MovieClip {

var mLoader:Loader = new Loader();  
var mRequest:URLRequest = new URLRequest(“xxx.swf”);  
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);  
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);  
mLoader.contentLoaderInfo.addEventListener( Event.ADDED\_TO\_STAGE, this.loadComplete );  
mLoader.load(mRequest);

function onCompleteHandler(loadEvent:Event) {  
addChild(loadEvent.currentTarget.content);  
}  
function onProgressHandler(mProgress:ProgressEvent) {  
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;  
trace(percent);  
lbar.scaleX = percent;  
}

function loadComplete( e : Event ):void {

```
this.addChild( this.appLoader );

```

}  
}  
}

---

<div class="post-metadata">

### Author: ![dail](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@dail](https://forum.kirupa.com/u/dail)
#### Post date: [July 11, 2008, 8:22am UTC](https://forum.kirupa.com/t/preloader-problem-with-as3-document-classes/265664/2 "2008-07-11T08:22:20Z")

</div>

Try the INIT event, instead of complete, as this lets the loaded swf’s AS initialise.

---

<div class="post-metadata">

### Author: ![weno42](https://avatars.discourse-cdn.com/v4/letter/w/74df32/32.png) [@weno42](https://forum.kirupa.com/u/weno42)
#### Post date: [July 11, 2008, 10:05am UTC](https://forum.kirupa.com/t/preloader-problem-with-as3-document-classes/265664/3 "2008-07-11T10:05:16Z")

</div>

Thanks Dail. And interesting idea but it still returns Error 1009. Do I need to change the code more to make this work?
