Основной прелоадер вообще без понятий, что там будет загружаться в главном классе.
Надо объединить все загружаемые данные, чтоб выводилось только один прелоадер.
Код прелоадера:
Код AS3:
public class Preloader extends MovieClip
{
public var W:int = 0;
public var H:int = 0;
private var $container:MovieClip = new MovieClip();
private var $percent:TextField = new TextField();
public function Preloader()
{
if (stage)
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
}
W = stage.stageWidth;
H = stage.stageHeight;
addEventListener(Event.ENTER_FRAME, checkFrame);
loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);
loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
stage.addChild($container);
$container.addChild($percent);
$percent.x = W / 2;
$percent.y = H / 2;
}
private function ioError(e:IOErrorEvent):void
{
trace(e.text);
}
private function progress(e:ProgressEvent):void
{
$percent.htmlText = Math.round(e.bytesLoaded / e.bytesTotal * 100) + "%"
}
private function checkFrame(e:Event):void
{
if (currentFrame == totalFrames)
{
TweenNano.to($container, 0.5, {alpha: 0});
stop();
loadingFinished();
}
}
private function loadingFinished():void
{
removeEventListener(Event.ENTER_FRAME, checkFrame);
loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progress);
loaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, ioError);
stage.removeChild($container);
$container = null;
// TODO hide loader
startup();
}
private function startup():void
{
gotoAndStop(2);
var mainClass:Class = getDefinitionByName("Main") as Class;
addChild(new mainClass() as DisplayObject);
}
}
И код основного класса:
Код AS3:
public function Main():void
{
super();
if (super.stage)
super.addEventListener(Event.COMPLETE, this.init);
else
super.addEventListener(Event.ADDED_TO_STAGE, this.init);
}
private function init(e:Event = null):void
{
super.removeEventListener(Event.ADDED_TO_STAGE, this.init);
$ContextMenu.hideBuiltInItems();
contextMenu = $ContextMenu;
stage.showDefaultContextMenu = false;
W = stage.stageWidth;
H = stage.stageHeight;
$Loader = new LoaderMax({name: "MainLoader", onProgress: progressHandler, onComplete: completeHandler, onError: errorHandler})
$Loader.append(new XMLLoader("xml/site.xml", {name: "SIteXml"}));
$Loader.append(new ImageLoader("assets/bg/1.jpg", {name: "Backgrounds", width: W, height: H, alpha: 0}));
$Loader.append(new MP3Loader("assets/music/1.mp3", {name: "Music"}));
$Loader.load();
}
public function progressHandler(e:LoaderEvent):void
{
trace("progress: " + Math.round(e.target.progress) * 100);
}