Loading an XML file and populating controls *before* application loads

I’m trying to create a flex application that preloads an XML file and populates some custom controls before displaying the page to the user. I’m trying to avoid having the controls resize as they populate while the user is viewing.

I have tried to create a custom preloader that, before dispatching Event.COMPLETE, loads the XML file and makes it available to be populated by the application. The problem is that I can’t figure out how to get the application to “block” so that I can populate the controls at a point in the life cycle before they are displayed. My best guess was that I would start loading the XML in the preloaders onInitComplete method and hold off on firing the Event.COMPLETE event until after the XML was loaded. However, the attached code illustrates that the applications creationComplete event is fired before the preloader’s onInitComplete event meaning that the only application event available for populating the controls with the XML data is applicationComplete and the controls are already visible which results in components being resized and populated in view of the user.

I’m wondering if there is another way to ensure that the XML data is loaded before the application renders the controls for the first time.
Attach Code

**************************** Main.mxml ********************************

<?xml version=“1.0” encoding=“utf-8”?>
<mx:Application xmlns:mx=“http://www.adobe.com/2006/mxml” layout=“absolute”
preloader=“CustomPreloader”
initialize=“onInitialize()”
creationComplete=“onCreationComplete()”
applicationComplete=“onApplicationComplete()”>

<mx:Script>
<![CDATA[

public function onInitialize():void
{
trace(“Application INITIALIZE.”);
}

public function onCreationComplete():void
{
// CAN’T populate controls with XML here because XML has not been loaded yet
trace(“Application CREATION COMPLETE.”);
}

public function onApplicationComplete():void
{
// CAN populate controls with XML here but they are apparently already created/visible
trace(“Application APPLICATION COMPLETE.”);
}
]]>
</mx:Script>
</mx:Application>

**************************** CustomPreloader.as **************************
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
import mx.events.*;
import mx.preloaders.Preloader;
import mx.preloaders.DownloadProgressBar;

public class CustomPreloader extends DownloadProgressBar {

public function CustomPreloader()
{
}

override public function set preloader( preloader:Sprite ):void
{
preloader.addEventListener( ProgressEvent.PROGRESS , onDownloadProgress );
preloader.addEventListener( Event.COMPLETE , onDownloadComplete );
preloader.addEventListener( FlexEvent.INIT_PROGRESS , onInitProgress );
preloader.addEventListener( FlexEvent.INIT_COMPLETE , onInitComplete );
}

private function onDownloadProgress( event: ProgressEvent ):void {}

private function onDownloadComplete( event:Event ):void {}

private function onInitProgress( event:Event ):void {}

private function onInitComplete( event:Event ):void
{
// Start loading XML here
trace(“Preloader INIT COMPLETE”);

// Execute this statement in another event handler after XML is loaded
// dispatchEvent( new Event( Event.COMPLETE ) );
}

}

}