You just need to use root.loaderInfo
's bytesTotal
and bytesLoaded
properties.
When they are equal to eachother, you've loaded 100% of the SWF and you can manage what should happen next accordingly.
Sample:
package
{
import flash.display.Sprite;
import flash.events.Event;
/**
* Document class.
*/
public class Document extends Sprite
{
// Constructor.
public function Document()
{
addEventListener(Event.ENTER_FRAME, _loadStatus);
}
// Manage the current status of the preloader.
private function _loadStatus(e:Event):void
{
if(loadPercent >= 1)
{
removeEventListener(Event.ENTER_FRAME, _loadStatus);
beginApplication();
}
}
// Load complete, being the application here.
protected function beginApplication():void
{
trace("Loaded.");
}
// Returns a number representing current application load percentage.
protected function get loadPercent():Number
{
return root.loaderInfo.bytesLoaded / root.loaderInfo.bytesTotal;
}
}
}
I must also note that exporting all your library symbols on the first frame is a bad idea - you need to make sure they aren't exported on the first frame.
Bonus: Having the above class as the base class of your actual document class makes for a really tidy application entry point (where you begin coding your application):
public class MyDocument extends Document
{
override protected function beginApplication():void
{
// Application has loaded.
// Your initialize code here.
//
//
}
}