mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
134 lines
3.8 KiB
ActionScript
134 lines
3.8 KiB
ActionScript
package loader
|
|
{
|
|
import com.sbi.loader.FileServerEvent;
|
|
import flash.display.Loader;
|
|
import flash.display.LoaderInfo;
|
|
import flash.display.MovieClip;
|
|
import flash.events.Event;
|
|
import localization.LocalizationManager;
|
|
|
|
public class JCDefHelper
|
|
{
|
|
|
|
private var _id:uint;
|
|
|
|
private var _def:Object;
|
|
|
|
private var _callback:Function;
|
|
|
|
private var _passback:Object;
|
|
|
|
private var _loadImage:Boolean;
|
|
|
|
private var _loader:Loader;
|
|
|
|
public function JCDefHelper()
|
|
{
|
|
super();
|
|
}
|
|
|
|
public function get id() : int
|
|
{
|
|
return this._id;
|
|
}
|
|
|
|
public function get def() : Object
|
|
{
|
|
return this._def;
|
|
}
|
|
|
|
public function init(id:uint, callback:Function = null, loadImage:Boolean = false, passback:Object = null) : void
|
|
{
|
|
this._id = id;
|
|
this._callback = callback;
|
|
this._passback = passback;
|
|
this._loadImage = loadImage;
|
|
this._loader = new Loader();
|
|
JCFileServer.instance.addEventListener(FileServerEvent.ON_NEW_DATA,this.handleData,false,0,true);
|
|
if(loadImage)
|
|
{
|
|
JCFileServer.instance.requestFileWithExtension(this._id,false,FileServerEvent.JSON_TYPE,"images/");
|
|
}
|
|
else if(id == LocalizationManager.currentLanguage)
|
|
{
|
|
JCFileServer.instance.requestFileWithExtension(this._id,false,FileServerEvent.AMF3_TYPE,"index/");
|
|
}
|
|
else
|
|
{
|
|
JCFileServer.instance.requestFileWithExtension(this._id,false,FileServerEvent.AMF3_TYPE,"amf/");
|
|
}
|
|
}
|
|
|
|
public function destroy() : void
|
|
{
|
|
JCFileServer.instance.removeEventListener(FileServerEvent.ON_NEW_DATA,this.handleData);
|
|
this._callback = null;
|
|
this._passback = null;
|
|
this._loader = null;
|
|
}
|
|
|
|
public function deleteIndexFileFromCache() : void
|
|
{
|
|
JCFileServer.instance.clearFromCache("index/",1);
|
|
}
|
|
|
|
private function handleData(fse:FileServerEvent) : void
|
|
{
|
|
if(fse.id == this._id && fse.success)
|
|
{
|
|
JCFileServer.instance.removeEventListener(FileServerEvent.ON_NEW_DATA,this.handleData);
|
|
if(!this._loadImage)
|
|
{
|
|
fse.data.position = 0;
|
|
this._def = fse.data.readObject();
|
|
this.onComplete();
|
|
}
|
|
else
|
|
{
|
|
this._loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onBytesLoaded);
|
|
this._loader.loadBytes(fse.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function onBytesLoaded(evt:Event) : void
|
|
{
|
|
var l:LoaderInfo = evt.target as LoaderInfo;
|
|
this._def = new MovieClip();
|
|
this._def.addChild(l.content);
|
|
if(this._def.hasOwnProperty("__rslPreloader") && Boolean(this._def.__rslPreloader))
|
|
{
|
|
this._def.addEventListener(Event.ENTER_FRAME,this.onFrame);
|
|
}
|
|
else
|
|
{
|
|
this.onComplete();
|
|
}
|
|
}
|
|
|
|
private function onFrame(e:Event) : void
|
|
{
|
|
if(this._def.__rslPreloader == null)
|
|
{
|
|
this._def.removeEventListener(Event.ENTER_FRAME,this.onFrame);
|
|
this.onComplete();
|
|
}
|
|
}
|
|
|
|
private function onComplete() : void
|
|
{
|
|
if(this._passback != null)
|
|
{
|
|
this._def.defHelper = this;
|
|
this._def.passback = this._passback;
|
|
}
|
|
if(this._callback != null)
|
|
{
|
|
this._callback(this._def);
|
|
this._callback = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|