views:

50

answers:

1

I know how to setup a preloader and I have that working. But when I debug the flash application and simulate a download, it has a blank background until a few seconds have passed.

I know it is "downloading" the swf file and I'm wondering if I can show a progress bar for that, or do I need to have the swf file as small as possible and pre load everything needed and have all assets as a separate file I fetch?

I found something with ProgressEvent.PROGRESS but this only loads after the flash file is finished downloading.

+2  A: 

Internally, the stuff inside a SWF is separated into frames, and when the Flash player is loading a SWF, it will start displaying and executing contents for frames as soon as they're loaded, even if later ones aren't finished yet. So as long as your preloader is stored earlier in the early frames of the SWF, and your heavy contents are stored later, then showing a preloader is very possible.

The problem you're probably running into is, if you build contents in a reasonably usual sort of way, then all your class objects get stored in the first frame. The easiest way to change this is in your FLA file, under Publish Settings > Flash > AS3 Settings, there is a dialog for "Export classes in frame:". If you change that setting from 1 to, say, 5, then you can put a simple preloader (using frame scripts) on the first couple frames of the root timeline, and make sure everything using classes is placed somewhere after the 5th frame.

If you'd rather not use frame scripts in the preloader, then using a class-based preloader is also possible, but then you need to go into the properties dialog of each object that's linked to a class, and uncheck the "Export in frame 1" option, and then make sure it's placed somewhere in the timeline hierarchy to make sure it gets exported, which is all a bit more of a pain. Naturally the class object representing the preloader would still need to be exported to the first frame.

Or you can do an end-run around the whole issue, and make your preloader as a separate shell SWF, which simply loads itself, then loads the actual content and displays a loader bar. Often people choose this option if they'd like to reuse the preloader.

fenomas
Thank you, a great answer.
Ólafur Waage