I'm sure this has been asked before but I can't find it. I'd like to show a SWF movieclip in a Flex preloader.

I've extended SparkDownloadProgressBar and all I'm getting is a white screen and then eventually the app loads.

Here is what I have so far:

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

    import mx.preloaders.SparkDownloadProgressBar;

    public class MyPreloader extends SparkDownloadProgressBar
        public function MyPreloader()
            //backgroundImage = PreloaderGfx;
            //backgroundImage = "butterfly.swf";
            //backgroundColor = 0xFF0000;
            //visible = true;

        //[Embed(source="/runninghorses.swf", symbol="PreloaderGfx")]
        private var PreloaderGfx:Class;

        override public function initialize():void {

        override protected function createChildren():void {
            //throw new Error();
            var displayObject:DisplayObject = getChildAt(0);

            trace("d width:" + displayObject.width);
            trace("d height:" + displayObject.height);

            if (displayObject is PreloaderGfx) {


        override protected function showDisplayForDownloading(elapsedTime:int, event:ProgressEvent):Boolean {
                    trace("showDisplayForDownloading: elapsedTime = " + elapsedTime);
                    trace("showDisplayForDownloading:" + event.bytesLoaded + " " +  event.bytesTotal + " " +  (event.bytesLoaded < event.bytesTotal / 2));
            return elapsedTime > 100 &&
                event.bytesLoaded < event.bytesTotal / 2;


First, don't call createChildren() in the initialize() method. createChildren() will be called by the Flex framework automatically, no need to call it twice and it's not how it is supposed to work anyways. In your case just remove your overridden initialize method completely.

Your main problem is that you have only embedded the swf but it's not on stage yet. Embed will just compile your asset to your swf but won't display it. You will need to add it yourself in the createChildren(). And you would need to wrap your swf into some kind of UIComponent so you can add it to stage. An Image might be the easiest solution (untested, just to give you an idea):

override protected function createChildren():void 

    var img:Image = new Image();
    img.source = PreloaderGfx;

Your Answer

