Thought I might answer my own question here.
I initialized everything in the preloader, and this looks perfectly ok to me. Please let me know if you have any suggestions or remarks.
Hope this may help someone else who's in the same situation
Preloader.as (irrelevant code omitted)
package com.thesedays.web2011
{
// import statements
/**
* @author Sven Dens - These Days
*/
public class Preloader extends MovieClip
{
// events constants
public static const STORE_CONFIGURATION:String = "event/store/configuration";
public static const BACKGROUND_SET:String = "event/background/set";
// Get a facade instance for this application
private var _facade:ApplicationFacade = ApplicationFacade.getInstance( Web2011.NAME );
// main application class
private var _main:Class;
// application class instance
private var _app:Object;
// stage assets for preloading
private var _loadingAnimation:TDLoader;
private var _background:Bitmap;
// preloader byte counters
private var _swfPercentLoaded:Number;
private var _backgroundPercentLoaded:Number;
private var _dataPercentLoaded:Number;
private var _totalProgress:Number;
// the configuration that was received from the flashvars (or default config)
private var _config:ConfigurationVO;
// greensock Imageloader for the background image used in the preloader
private var _backgroundLoader:ImageLoader;
//-------------------------------------
// CONSTRUCTOR
//-------------------------------------
public function Preloader()
{
// stop the timeline
stop();
// initialize the byte counters
_swfPercentLoaded = 0;
_backgroundPercentLoaded = 0;
_dataPercentLoaded = 0;
_totalProgress = 0;
// start the PureMVC apparatus
_facade.startup(this);
// set scale mode
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
// activate plugins
TweenPlugin.activate([AutoAlphaPlugin]);
// load policies and set permissions for YouTube
Security.loadPolicyFile('http://www.youtube.com/crossdomain.xml');
Security.allowDomain("*.youtube.com");
Security.allowDomain("*.ytimg.com");
// load the fonts
loadFonts();
// initialize application settings
readFlashVars();
// listen for enter frame
addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true);
// listen for resize
stage.addEventListener(Event.RESIZE, onResize, false, 0, true);
}
private function onLoadingAnimationFinished(evt:Event) : void
{
// remove event listener
_loadingAnimation.removeEventListener(TDLoader.ANIMATION_FINISHED, onLoadingAnimationFinished);
// advance to frame 2
nextFrame();
// fade out the preloader and render the website
renderWebsite();
}
private function renderWebsite():void
{
_main = Class(getDefinitionByName("com.thesedays.web2011.Web2011"));
if(!_main) throw new Error("Could not retrieve the main application class com.thesedays.web2011.Web2011. Check your code!");
// instantiate the website
_app = new _main();
addChild(_app as DisplayObject);
// and call the startup method
_app.startup();
// now clean up the preloader stuff
var i:int = numChildren;
while(--i > -1)
{
if(getChildAt(i) == _loadingAnimation)
{
removeChildAt(i);
_loadingAnimation = null;
break;
}
}
i = NaN;
_swfPercentLoaded = NaN;
_backgroundPercentLoaded = NaN;
_dataPercentLoaded = NaN;
_totalProgress = NaN;
_config = null;
}
StartupCommand
package com.thesedays.web2011.controller
{
//import statements
/**
* @author Sven Dens - These Days
*/
public class StartupCommand extends SimpleCommand
{
override public function execute ( note:INotification ) : void
{
var preloader:Preloader = note.getBody() as Preloader;
if(!preloader) throw new ArgumentError("The object passed to the startup method could not be cast as a Preloader, check your code!");
// register a mediator for the Preloader
facade.registerMediator(new PreloaderMediator(preloader));
// register a proxy to store the configuration that was provided with flashvars
facade.registerProxy(new ConfigurationProxy());
// register a proxy to store the application's data that will be preloaded
facade.registerProxy(new ApplicationDataProxy());
// and register a proxy to store the backgrounds that will be loaded from the server
facade.registerProxy(new BackgroundsProxy());
}
}
}
And then the main class, Web2011.as
package com.thesedays.web2011
{
import flash.display.MovieClip;
/**
* @author Sven Dens - These Days
*/
[Frame(factoryClass="com.thesedays.web2011.Preloader")]
public class Web2011 extends MovieClip
{
// App name
public static const NAME:String = "Web2011";
public function Web2011()
{
}
public function startup():void
{
trace("application started");
}
}
}