# AS3 Preloading in Document Class

**URL:** <https://forum.kirupa.com/t/as3-preloading-in-document-class/283818>\
**Category:** flash\
**Created:** [March 11, 2009, 2:17pm UTC](https://forum.kirupa.com/t/as3-preloading-in-document-class/283818 "2009-03-11T14:17:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mycaptainkite](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@mycaptainkite](https://forum.kirupa.com/u/mycaptainkite)\
**Post date:** [March 11, 2009, 2:17pm UTC](https://forum.kirupa.com/t/as3-preloading-in-document-class/283818/1 "2009-03-11T14:17:14Z")

</div>

Hi, I’m working on a flash element for a website… I need to preload but can’t seem to get the ProgressEvent to work correctly.

I have all my actionscript in the document class, and I’m basically using this code, but it seems like the percent is just immediately going to 100% and loading… it’s not actually preloading when I use ‘Simulate download’.

```auto

public function DocClass() : void {
            this.loaderInfo.addEventListener(Event.INIT, addPreloader);
            this.loaderInfo.addEventListener(Event.COMPLETE, LoadComplete);
            this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, Loading);
}

private function addPreloader(e:Event):void {
            preloader = new Preloader();
            addChild(preloader);
            preloader.x = stage.stageWidth / 2 ;
            preloader.y = stage.stageHeight / 2;
}

private function Loading(e:ProgressEvent):void {            
            var percent:Number = Math.round(e.bytesLoaded / e.bytesTotal * 100);
            trace(percent);
            
            preloader.preloader_text.percentage.text = percent;
}

private function LoadComplete(e:Event) : void {
           // Rest of the code for element
}

```

If anyone could help me out that would be awesome. Thanks!
