AS3 Preloading Issues with Dynamic Class Files

Hi all,

I seem to be getting tripped up on this and hope someone can help me out. I have a large project with a number of MovieClips in it that
are each linked to class files that provide their internal logic. I am trying to preload all of these MovieClips by creating a preloader on the
first few frames of my main timeline. Then when all the assets have loaded in, instantiate these MovieClips at runtime using the ‘new’ operator.

The trouble I am having is that the classes that are linked to the MovieClips in the library are instantiating however the MovieClips themselves
are not appearing after I attach them to the stage using addChild().

Here is a very simple example of what I am trying to do:

My document class is ApplicationMain :


package {

    import flash.display.MovieClip;
    import flash.display.DisplayObject;
    import flash.events.*

    public class ApplicationMain extends MovieClip {
        
        public function ApplicationMain()
        {
            stop();
            trace('ApplicationMain Created');
            loaderInfo.addEventListener(ProgressEvent.PROGRESS, preloadApplication);
            loaderInfo.addEventListener(Event.COMPLETE, initApplication);
        }
        
        private function preloadApplication(evt:Event)
        {
            trace('Preloading');
        }
        
        private function initApplication(evt:Event)
        {
            trace('Loading Complete');
            gotoAndStop(6);
            var dmc:DynamicMovieClip = new DynamicMovieClip();
            addChild(dmc as DisplayObject); 
        }
    }
}

In my library I have one MovieClip within which is a 2MB jpeg to give it some weight. This MovieClip is associated with
the class file DynamicMovieClip which simply traces itself out upon instantiation.


package {

    import flash.display.MovieClip;

    public class DynamicMovieClip extends MovieClip {
        
        public function DynamicMovieClip()
        {
            trace('DynamicMovieClip Created');
        }
    }
}

So here is the kicker. I have deselected “export in first frame” on the DynamicMovieClip in the library so it doesn’t defeat my preloader.
Then I placed a copy of that MC on the stage at frame 5 so that it is included in the swf when it is compiled.

In my document class I skip OVER frame 5 when everything has finished loading, however when I go to create this DynamicMovieClip
with code using the ‘new’ operator the class constructor fires but the MC does not get attached to the stage using AddChild().

What is the best practice for instantiating dynamic MovieClips at runtime in AS3 that are not exported in the first frame so that they
may be preloaded before being created?

If anyone can shine some light on this I’d really appreciate it.

Thanks,
Stephen