I encountered a problem involving flex custom preloaders.
The context I was using was as follows:
- I created a preloader.swf in flash with a 100 frames to show a progressbar evolution.
- I embedded that preloader.swf in my flex app. Read more about this here
This all worked fine when I ran my application locally.
However, the problem showed itself when deploying my app to my webserver (thus no longer running it locally).
The unintended behavior was that the preloader would not show up until my app was nearly fully loaded, and it then popped up for about a second @ 100% full.
I tried all sorts of different approaches.
- Extending mx.preloaders.DownloadProgressBar
- Creating a new MovieClip that implemented IPreloaderDisplay. More about this here
- Creating a loader .swf that contained the preloader, and loading in my app from there
- Using Charles to monitor request and responses
However none of these solutions seemed to work.
After searching a long time for what the fudge could be causing this problem, I stumbled upon the following blog posts:
As it turns out, the problem isn’t caused by Flash Player or by Flex. It is caused by your server setup.
If you have gzip compression enabled on your server (for speeding up requests and responses), the problem occurs.
What the gzip compression does is compress your already compressed binary .swf file, thus screwing up the loading procedure from an actionscript point of view.
Actually gzip compression doesn’t enhance performance in any way because a .swf is as compressed as it can be.
This also counts for numerous other already compressed files that can’t be compressed any further (.jpg,.gif,.flv,.png,..)
So the solution is rather simple. You can just add a .htaccess file to the root of your public directory to ensure that .swf files (and any other already compressed files) will no longer be compressed.
All that has to be in this file is the following:
# Don't compress images/flash SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png|swf|flv)$ no-gzip dont-vary
Et voila, you have disabled the gzip compression and fixed your preloader bug because it’s working now.
This really was a pain in the *ss for me, as I spent 2 days looking for a solution.
I hope this post can save you the trouble I went through