package cn.ishion.component
{
import cn.ishion.Util;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import mx.events.FlexEvent;
import mx.events.RSLEvent;
import mx.preloaders.DownloadProgressBar;
public class TestPreloader extends DownloadProgressBar
{
private var _loadConfig:String="加载配置文件";
public function TestPreloader()
{
super();
super.label="加载";
DownloadProgressBar.initializingLabel="应用加载完成";
}
private var _preloader:Sprite;
override public function set preloader(value:Sprite):void{
_preloader = value;
value.addEventListener(ProgressEvent.PROGRESS, progressHandler);
value.addEventListener(Event.COMPLETE, completeHandler);
value.addEventListener(RSLEvent.RSL_PROGRESS, rslProgressHandler);
value.addEventListener(RSLEvent.RSL_COMPLETE, rslCompleteHandler);
value.addEventListener(RSLEvent.RSL_ERROR, rslErrorHandler);
value.addEventListener(FlexEvent.INIT_PROGRESS, initProgressHandler);
value.addEventListener(FlexEvent.INIT_COMPLETE, initCompleteHandler);//重写这个事件的方法
}
public function initCompleteHandler(event:FlexEvent):void{
super.label=_loadConfig;
//加载配置文件
var util:Util=new Util();
util.addEventListener(ProgressEvent.PROGRESS,progressHandler);
util.addEventListener(Event.COMPLETE,onLoadConfig);
util.init();
}
private function onLoadConfig(event:Event):void{
//mx.controls.Alert.show("loadConfig");
trace("loadConfig");
this.dispatchEvent(new Event(Event.COMPLETE)); //关键这句,告诉SystemManager应用初始化完成
//否则进入不了主程序,一直卡那
}
override protected function initProgressHandler(event:Event):void{
super.initProgressHandler(event);
}
override protected function showDisplayForDownloading(elapsedTime:int, event:ProgressEvent):Boolean{
return true;
}
override protected function showDisplayForInit(elapsedTime:int, count:int):Boolean{
return true;
}
}
}
package cn.ishion
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
[Event(name="progress",type="flash.events.ProgressEvent")]
[Event(name="complete",type="flash.events.Event")]
public class Util extends EventDispatcher
{
public static var imagePath:String;
public function Util()
{
}
public function init():void{
var urlLoader:URLLoader=new URLLoader();
urlLoader.addEventListener(Event.COMPLETE,onResult);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR,ioError);
urlLoader.addEventListener(ProgressEvent.PROGRESS,onProgress);
urlLoader.load(new URLRequest("activeConfig.xml"));
}
private function onProgress(event:ProgressEvent):void{
this.dispatchEvent(event);
}
public function onResult(event:Event):void{
//
var loader:URLLoader=event.target as URLLoader;
var configxml:XML=XML(loader.data);
imagePath=configxml.imagePath;
this.dispatchEvent(event);
}
public function ioError(event:IOErrorEvent):void{
this.dispatchEvent(event);
}
}
}