# Document Class Trouble :\\

**URL:** <https://forum.kirupa.com/t/document-class-trouble/255986>\
**Category:** flash\
**Created:** [March 28, 2008, 8:45pm UTC](https://forum.kirupa.com/t/document-class-trouble/255986 "2008-03-28T20:45:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jtbrack](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@Jtbrack](https://forum.kirupa.com/u/Jtbrack)\
**Post date:** [March 28, 2008, 8:45pm UTC](https://forum.kirupa.com/t/document-class-trouble/255986/1 "2008-03-28T20:45:51Z")

</div>

I’m rather new to ActionScript 3 and trying to learn how to code away from the timeline. Needless to say it’s been a little frustrating.

In this document class, all I’m trying to do is set up a preLoader and a basic background image. Everything works fine except for when I add my preLoader code, which works when placed on a timeline.

```auto
package {
    import flash.events.*;
    import flash.display.*;

    public class Positions extends MovieClip {
        var bg:backgroundMovie = new backgroundMovie();
        var bgBlue:bgColor = new bgColor();
        var custom_animation:preloader = new preloader();
                
        public function Positions():void {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.showDefaultContextMenu = false;
            stage.align = StageAlign.TOP_LEFT;
            
            addChild(bgBlue);
            addChild(custom_animation);
            bgBlue.width = stage.stageWidth;
            bgBlue.height = stage.stageHeight;
            bgBlue.x = stage.stageWidth/2;
            bgBlue.y = stage.stageHeight/2;
            custom_animation.x = stage.stageWidth/2;
            custom_animation.y = stage.stageHeight/2;
            
            stage.addEventListener(Event.RESIZE, resizeHandler);
            addEventListener(Event.ENTER_FRAME, loading);
        }
            private function loading(event:Event):void {
                var bytestotal = stage.loaderInfo.bytesTotal;
                var bytesloaded = stage.loaderInfo.bytesLoaded;
                var sclbar = Math.round(bytesloaded*100/bytestotal);
                custom_animation.gotoAndPlay(sclbar);
                if (bytesloaded >= bytestotal) {
                removeEventListener(Event.ENTER_FRAME, loading);
                removeChild(custom_animation);
                setup();
                }
            }
            
            private function resizeHandler(event:Event):void {
                var ratio:Number = bg.scaleX;
                bg.x = stage.stageWidth/2;
                bg.y = stage.stageHeight/2;
                bg.width = stage.stageWidth;
                bg.scaleY = ratio;
            }
            
            private function setup():void {
                addChild(bg);
                bg.x = stage.stageWidth/2;
                bg.y = stage.stageHeight/2;
                bg.width = stage.stageWidth;
            }
    }
}

```

When I load up the page, I only get a blank, white screen while the loader is in action. After it meets it’s “if” condition, it runs the “setup” function. My only problem is to get custom\_animation and bgBlue to show up while the loader is working, as they’re nowhere to be seen. I’m quite perplexed :-/.
