New Movieclip()

More about preloading in Flash CS3

42 Comments Posted by Koen on 30 April , 2007

In one of my blog posts I already told you a bit about preloading with the actionscript 3.0 way. But there is a bit more to tell about Flash CS3 and preloading.

1. Preloading the whole SWF Movie :

If you want to write a preloader for your whole movie (eg with a lot of assets on frames), the simplest thing to do is put your preloader in your document class of the movie because there is a LoaderInfo object available for the instance of the main class of the SWF file. The instance of the main class of the SWF file has NO Loader object, the loaderInfo property is the only way to access the LoaderInfo.

How does this look in code? Well we make a small document class here as an example:

As you see we can access the loaderInfo property and add some eventListeners to it to know when some progress is made. When the content is fully loaded then the initApplication method of our document class is executed. The only thing you still must do now is specify this class as the document class to use. In the properties panel you can set the Document class to eg “com.newmovieclip.Preloader”.

2. Preloading runtime loaded assets

Imagine you have a lot of assets in your library that are loaded at runtime. Then the progress event of the loaderInfo property in your document class will not be triggered because all the assets are default exported on the first frame ( this is still the same in CS3). 😦

One widely spread solution for this is changing the” export in first frame” option and force the assets to load in an other frame by explicit place them on the stage. (same technique as in Flash8). Another option is to use a wrapper SWF that loads your main swf with the approach I explained in this article. You can do the loading in the document class of the wrapper. I personally think a wrapper SWF is still far most the best approach for good preloading.
[null, {"document_url": "https://newmovieclip.wordpress.com/2007/04/30/more-about-preloading-in-flash-cs3/", "unformatted_src": "https://newmovieclip.files.wordpress.com/2010/11/koen_de_weggheleire_10.jpg", "src": "https://newmovieclip.files.wordpress.com/2010/11/koen_de_weggheleire_10.jpg", "formatted_filename": "koen de weggheleire", "rendered_width": 250, "rendered_height": 250}, null, {"document_url": "https://newmovieclip.wordpress.com/2007/04/30/more-about-preloading-in-flash-cs3/", "unformatted_src": "https://newmovieclip.files.wordpress.com/2010/11/facebook.png", "src": "https://newmovieclip.files.wordpress.com/2010/11/facebook.png", "formatted_filename": "facebook", "rendered_width": 145, "rendered_height": 48}, null, {"document_url": "https://newmovieclip.wordpress.com/2007/04/30/more-about-preloading-in-flash-cs3/", "unformatted_src": "https://newmovieclip.files.wordpress.com/2008/09/air_cookbook_01.jpg", "src": "https://newmovieclip.files.wordpress.com/2008/09/air_cookbook_01.jpg", "formatted_filename": "air cookbook"}, {"document_url": "https://newmovieclip.wordpress.com/2007/04/30/more-about-preloading-in-flash-cs3/", "unformatted_src": "https://newmovieclip.files.wordpress.com/2010/11/flashcs4airdevelopment.png", "src": "https://newmovieclip.files.wordpress.com/2010/11/flashcs4airdevelopment.png", "formatted_filename": "flashcs airdevelopment"}, {"document_url": "https://newmovieclip.wordpress.com/2007/04/30/more-about-preloading-in-flash-cs3/", "unformatted_src": "https://newmovieclip.files.wordpress.com/2007/11/894-6-jacobs_deweggheleire.jpg", "src": "https://newmovieclip.files.wordpress.com/2007/11/894-6-jacobs_deweggheleire.jpg", "formatted_filename": "jacobs deweggheleire"}, null]