Customizing the Preloader

By default, all Flex applications use a standard preloader progress bar screen while the application itself is downloading. If you choose, you can create a custom preloader screen. This is possible and relatively simple to accomplish. There are two steps:

  1. Create a class that subclasses mx.preloaders.DownloadProgressBar or subclasses Sprite and implements the mx.preloaders.IPreloaderDisplay interface.

  2. Set the preloader property of the Application object to the path to the class from the preceding step.

The first of these two steps is the more complicated of the two, but it is still reasonably trivial. You have two options: either subclass mx.preloaders.DownloadProgressBar or create a Sprite subclass that also implements mx.preloaders.IPreloader. Let’s look at the DownloadProgressBar subclass first.

Technically you can subclass DownloadProgressBar as an all-purpose solution. However, from an academic standpoint, it’s better to subclass DownloadProgressBar only when you intend to customize the default preloader screen. When subclassing DownloadProgressBar you’ll want to ensure that you always called the super constructor from the constructor of the subclass:

package com.oreilly.programmingflex.preloader {

    import mx.preloaders.DownloadProgressBar;

    public class CustomPreloaderSubclass extends DownloadProgressBar {

        public function CustomPreloaderSubclass() {
            super();
        }

    }
}

The super constructor ensures that the proper event handlers are configured for the class. Then ...

Get Programming Flex 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.