And a new way to! (Damn that sounded cocky! Hahaha! )
I recently discovered a new way of prelaoding content in the Flash Player. By passing an extra argument to the compiler. At work an at home i use FDT for creating and compiling my Flash content and there was always the problem with preloading. There are several ways of how to go about it.
- Create a preloader.swf and let that file load in the main site/application. (As described here)
- Passing the loaderinfo (As described here)
And then there is the ‘frame two compiler’ method.Let me be clear, this is not something I have discovered or invented, merely something I have found.
Here is how to do it:
When compiling from within FDT and creating your launcher file (also included in the download at the end of this article) you can add extra arguments to the fcsh compiler. The standard line i use is:
-default-size 400 320 -default-frame-rate 31 -default-background-color 0xFFFFFF -library-path{flexSDK}/frameworks/locale /en_US
What you need to add to make use of the ‘frame two’ method is add the following (The stacktraces is not needed for the frame two option but very handy to use when debugging, I put it in standard in every project I use. ):
-verbose-stacktraces=true -frame two nl.funkymonkey.preloading.Application
What the above code does is it takes the class with the name (and classpath) of “nl.funkymonkey.preloading.Application” and places it on the second frame called “two”. You can use the “-frame” compiler option as many times as you want for adding even more frames. (For a second preloader or other content that needs to be loaded)
Make sure the MAIN_CLASS attribute is set yo your Preloader.as in your Application.launch file. Like so:
The code that makes sure the correct class file is loaded after the preloader is this:
protected var APP_CLASS : String = "nl.funkymonkey.preloading.Application";
private function init() : void {
trace( "this is the preloader" );
var AppClass : Class = Class( getDefinitionByName( APP_CLASS ) );
if(AppClass) {
var application : IApplication = new AppClass( ) as IApplication;
addChild( application as DisplayObject );
startApplication( application );
}
}
/**
* Start the application
*
* @param app:IApplication the application that is loaded
*/
protected function startApplication(app : IApplication) : void {
trace( "start app" );
app.start( );
}
The complete Eclipse FDT project, the launcher file including the compiler arguments and the complete code can be found here.This can also be used in Flash Builder or any other editor that allows you to pass arguments to the fcsh compiler.
Let me know if you run into any problems!




on Apr 11th, 2010 at 11:19 pm
[...] Dit blogartikel was vermeld op Twitter door Sidney de Koning. Sidney de Koning heeft gezegd: [new blog post] Preloaders: The best way of doing it: And a new way to! I recently discovered a new way of prelaod… http://bit.ly/c68Nkz [...]
on Jun 6th, 2010 at 7:51 pm
[...] (images, fonts, CSS, etc) Flash is visual. So you need to know how to manage assets with code. http://www.funky-monkey.nl/blog/2010/04/09/preloaders-the-best-way-of-doing-it/ http://www.funky-monkey.nl/blog/2008/05/05/font-embedding-in-as3/ [...]
on Jul 13th, 2010 at 10:35 pm
I’m following your instructions and when I go to build I get the following:
Error: a target file must be specified
Also, I am showing all hidden files and I don’t even see an Application.launch file.
Any links you can suggest so I can understand this more deeply.
I really wish FDT could make some of these things simpler. It’s a lot easier to understand and implement this stuff in Flash Develop.
on Jul 14th, 2010 at 3:19 pm
Hi Lilblacky,
When you choose ‘Run Configurations’ you should get a dialog box where you can set the BaseClass of your project. That is the target file. Once you set this you should be able to compile.
There is a bunch of information on Google on compiling with FDT. There is also a FDT Manual on the Powerflasher website, here is a link and here is the manual (PDF Alert!)
Good luck and happy coding
Sid