- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
public class AppLoader extends EventDispatcher {
private static var loaderInfo:LoaderInfo;
private static var progress_callback:Function;
private static var complete_callback:Function;
private static function progressHandler(event:ProgressEvent):void {
progress_callback((event.bytesLoaded / event.bytesTotal) * 100);
}
private static function completeHandler(event:Event = null):void {
loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progressHandler);
loaderInfo.removeEventListener(Event.COMPLETE, completeHandler);
complete_callback();
}
public static function initLoader(_loaderInfo:LoaderInfo, _progress_callback:Function, _complete_callback:Function):void {
loaderInfo = _loaderInfo;
progress_callback = _progress_callback;
complete_callback = _complete_callback;
if (loaderInfo.bytesLoaded < loaderInfo.bytesTotal) {
loaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
loaderInfo.addEventListener(Event.COMPLETE, completeHandler);
} else
complete_callback();
}
}