mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-20 17:37:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
@@ -0,0 +1,153 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.events.EventDispatcher;
|
||||
|
||||
public class BaseFileServer extends EventDispatcher
|
||||
{
|
||||
|
||||
private var _contentPath:String;
|
||||
|
||||
private var _loaderArray:Array;
|
||||
|
||||
private var _cacheArray:Array;
|
||||
|
||||
public function BaseFileServer(path:String)
|
||||
{
|
||||
super();
|
||||
this._contentPath = path;
|
||||
this._loaderArray = new Array();
|
||||
this._cacheArray = new Array();
|
||||
}
|
||||
|
||||
public function updatePath(path:String) : void
|
||||
{
|
||||
this._contentPath = path;
|
||||
}
|
||||
|
||||
public function clearFromCache(path:String, id:int) : void
|
||||
{
|
||||
if(Boolean(this._cacheArray[path]))
|
||||
{
|
||||
if(Boolean(this._cacheArray[path][id]))
|
||||
{
|
||||
delete this._cacheArray[path][id];
|
||||
}
|
||||
}
|
||||
if(Boolean(this._loaderArray[path]))
|
||||
{
|
||||
if(Boolean(this._loaderArray[path][id]))
|
||||
{
|
||||
delete this._loaderArray[path][id];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function requestFile(id:uint, noCache:Boolean = false, contentType:int = 0, useDeployVersion:Boolean = true) : void
|
||||
{
|
||||
var l:LoaderCacheEntry_URL = null;
|
||||
if(noCache || this.getFromCache(id) == false)
|
||||
{
|
||||
if(!(Boolean(this._loaderArray[this._contentPath]) ? this._loaderArray[this._contentPath][id] : false))
|
||||
{
|
||||
l = new LoaderCacheEntry_URL(this._contentPath + id,false);
|
||||
l.id = id;
|
||||
l.contentType = contentType;
|
||||
l.addEventListener(LoaderEvent.ON_LOAD_COMPLETE,this.onResultGetData);
|
||||
l.load("binary",useDeployVersion);
|
||||
if(this._loaderArray[this._contentPath] == null)
|
||||
{
|
||||
this._loaderArray[this._contentPath] = [];
|
||||
}
|
||||
this._loaderArray[this._contentPath][id] = {
|
||||
"l":l,
|
||||
"c":1
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
++this._loaderArray[this._contentPath][id].c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function requestFiles(ids:Array) : void
|
||||
{
|
||||
for(var i:int = 0; i < ids.length; )
|
||||
{
|
||||
this.requestFile(ids[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private function getFromCache(id:uint) : Boolean
|
||||
{
|
||||
var r:Object = this.searchCache(id);
|
||||
if(Boolean(r))
|
||||
{
|
||||
this.newEvent(r.id,r.data,true,r.contentType);
|
||||
}
|
||||
return r == null ? false : true;
|
||||
}
|
||||
|
||||
private function searchCache(id:uint) : Object
|
||||
{
|
||||
return Boolean(this._cacheArray[this._contentPath]) ? this._cacheArray[this._contentPath][id] : null;
|
||||
}
|
||||
|
||||
private function onResultGetData(le:LoaderEvent) : void
|
||||
{
|
||||
var c:int = 0;
|
||||
var e:FileServerEvent = new FileServerEvent(FileServerEvent.ON_NEW_DATA);
|
||||
e.id = le.entry.id;
|
||||
e.contentType = le.entry.contentType;
|
||||
var o:Object = le.entry.data;
|
||||
if(o == null)
|
||||
{
|
||||
e.success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.data = o;
|
||||
if(this._cacheArray[this._contentPath] == null)
|
||||
{
|
||||
this._cacheArray[this._contentPath] = [];
|
||||
}
|
||||
this._cacheArray[this._contentPath][e.id] = {
|
||||
"id":e.id,
|
||||
"data":o,
|
||||
"contentType":e.contentType
|
||||
};
|
||||
}
|
||||
var currObj:Object = this._loaderArray[this._contentPath][e.id];
|
||||
if(Boolean(currObj))
|
||||
{
|
||||
currObj.l.removeEventListener(LoaderEvent.ON_LOAD_COMPLETE,this.onResultGetData);
|
||||
c = int(currObj.c);
|
||||
this._loaderArray[this._contentPath][e.id] = null;
|
||||
while(c-- > 0)
|
||||
{
|
||||
this.newEvent(e.id,e.data,e.success,e.contentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function newEvent(id:int, data:*, success:Boolean, contentType:int = 0) : void
|
||||
{
|
||||
var ne:FileServerEvent = new FileServerEvent(FileServerEvent.ON_NEW_DATA);
|
||||
ne.id = id;
|
||||
ne.data = data;
|
||||
ne.success = success;
|
||||
ne.contentType = contentType;
|
||||
dispatchEvent(ne);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SingletonLock
|
||||
{
|
||||
|
||||
public function SingletonLock()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class FileServerEvent extends Event
|
||||
{
|
||||
|
||||
public static const ON_NEW_DATA:String = "OnNewData";
|
||||
|
||||
public static const JSON_TYPE:int = 0;
|
||||
|
||||
public static const PLAIN_TEXT_TYPE:int = 1;
|
||||
|
||||
public static const AMF3_TYPE:int = 2;
|
||||
|
||||
public var id:uint;
|
||||
|
||||
public var data:*;
|
||||
|
||||
public var success:Boolean = true;
|
||||
|
||||
public var contentType:int = 0;
|
||||
|
||||
public function FileServerEvent(type:String)
|
||||
{
|
||||
super(type);
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new FileServerEvent(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
public interface IResourceStackable
|
||||
{
|
||||
|
||||
function init(param1:Function) : void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class ImageServerEvent extends Event
|
||||
{
|
||||
|
||||
public static const ON_NEW_DATA:String = "OnNewData";
|
||||
|
||||
public static const ON_GLOBAL_PALETTE:String = "OnGlobalPalette";
|
||||
|
||||
public var id:uint;
|
||||
|
||||
public var layer:int;
|
||||
|
||||
public var imageData:*;
|
||||
|
||||
public var versionNum:int;
|
||||
|
||||
public var genericData:*;
|
||||
|
||||
public var frames:int;
|
||||
|
||||
public var success:Boolean = true;
|
||||
|
||||
public function ImageServerEvent(type:String)
|
||||
{
|
||||
super(type);
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new ImageServerEvent(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import com.sbi.graphics.ImageArray;
|
||||
import com.sbi.graphics.ImageArrayHelper;
|
||||
import com.sbi.graphics.PaletteHelper;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class ImageServerURL extends EventDispatcher
|
||||
{
|
||||
|
||||
private static var _instance:ImageServerURL;
|
||||
|
||||
private static const IMAGE_ARRAY_PATH:String = "imageArrays/";
|
||||
|
||||
private static const PALETTE_NAME:String = "paletteData";
|
||||
|
||||
private var _imageCacheArray:Array;
|
||||
|
||||
private var _loaderCacheArray:Array;
|
||||
|
||||
private var _layerInfo:Object;
|
||||
|
||||
public function ImageServerURL(lock:Class)
|
||||
{
|
||||
super();
|
||||
if(lock != SingletonLock)
|
||||
{
|
||||
throw new Error("Invalid Singleton access. Use ImageServerURL.instance.");
|
||||
}
|
||||
this._imageCacheArray = new Array();
|
||||
this._loaderCacheArray = new Array();
|
||||
}
|
||||
|
||||
public static function get instance() : ImageServerURL
|
||||
{
|
||||
if(!_instance)
|
||||
{
|
||||
_instance = new ImageServerURL(SingletonLock);
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public function set layerInfo(o:Object) : void
|
||||
{
|
||||
this._layerInfo = o;
|
||||
}
|
||||
|
||||
public function getLayerIndex(layerId:int) : int
|
||||
{
|
||||
return this._layerInfo[layerId];
|
||||
}
|
||||
|
||||
public function requestGlobalPalette() : void
|
||||
{
|
||||
var e:ImageServerEvent = null;
|
||||
var l:LoaderCacheEntry_URL = null;
|
||||
if(this.isGlobalPaletteCached())
|
||||
{
|
||||
e = new ImageServerEvent(ImageServerEvent.ON_GLOBAL_PALETTE);
|
||||
e.imageData = null;
|
||||
trace("imageServer dispatching cached game palette");
|
||||
dispatchEvent(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
l = new LoaderCacheEntry_URL(PALETTE_NAME);
|
||||
l.addEventListener(LoaderEvent.ON_LOAD_COMPLETE,this.onResultGetGamePalette);
|
||||
l.load();
|
||||
this._loaderCacheArray["palette"] = {"l":l};
|
||||
}
|
||||
}
|
||||
|
||||
public function requestImage(id:uint, bUseCache:Boolean = true) : void
|
||||
{
|
||||
var l:LoaderCacheEntry_URL = null;
|
||||
if(!bUseCache || this.getFromCache(id) == false)
|
||||
{
|
||||
if(!this._loaderCacheArray[id])
|
||||
{
|
||||
l = new LoaderCacheEntry_URL(IMAGE_ARRAY_PATH + id);
|
||||
l.id = id;
|
||||
l.addEventListener(LoaderEvent.ON_LOAD_COMPLETE,this.onResultGetImageData);
|
||||
l.load();
|
||||
this._loaderCacheArray[id] = {
|
||||
"l":l,
|
||||
"c":1
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
++this._loaderCacheArray[id].c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function requestImages(ids:Array) : void
|
||||
{
|
||||
for(var i:int = 0; i < ids.length; i++)
|
||||
{
|
||||
this.requestImage(ids[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private function getFromCache(id:uint) : Boolean
|
||||
{
|
||||
var e:ImageServerEvent = null;
|
||||
var r:Object = this.searchCache(id);
|
||||
if(Boolean(r))
|
||||
{
|
||||
e = new ImageServerEvent(ImageServerEvent.ON_NEW_DATA);
|
||||
e.id = r.id;
|
||||
e.imageData = r.imageData;
|
||||
e.frames = r.frames;
|
||||
e.layer = r.layer;
|
||||
e.success = e.imageData == null ? false : true;
|
||||
dispatchEvent(e);
|
||||
}
|
||||
return r == null ? false : true;
|
||||
}
|
||||
|
||||
private function isGlobalPaletteCached() : Boolean
|
||||
{
|
||||
return Boolean(PaletteHelper.gamePalette);
|
||||
}
|
||||
|
||||
private function searchCache(id:uint) : Object
|
||||
{
|
||||
return this._imageCacheArray[id];
|
||||
}
|
||||
|
||||
private function onResultGetGamePalette(e:LoaderEvent) : void
|
||||
{
|
||||
var ie:ImageServerEvent = null;
|
||||
var ba:ByteArray = null;
|
||||
var pal:ByteArray = null;
|
||||
var a1pal:ByteArray = null;
|
||||
var a2pal:ByteArray = null;
|
||||
var len:int = 0;
|
||||
var pos:int = 0;
|
||||
if(Boolean(e))
|
||||
{
|
||||
this._loaderCacheArray["palette"].l.removeEventListener(LoaderEvent.ON_LOAD_COMPLETE,this.onResultGetGamePalette);
|
||||
this._loaderCacheArray["palette"] = null;
|
||||
ie = new ImageServerEvent(ImageServerEvent.ON_GLOBAL_PALETTE);
|
||||
ba = e.entry.data as ByteArray;
|
||||
pal = new ByteArray();
|
||||
a1pal = new ByteArray();
|
||||
a2pal = new ByteArray();
|
||||
ba.position = 0;
|
||||
len = ba.readInt();
|
||||
pos = 4;
|
||||
pal.writeBytes(ba,pos,len);
|
||||
pal.position = 0;
|
||||
pos += len;
|
||||
ba.position = pos;
|
||||
len = ba.readInt();
|
||||
pos += 4;
|
||||
a1pal.writeBytes(ba,pos,len);
|
||||
a1pal.position = 0;
|
||||
pos += len;
|
||||
ba.position = pos;
|
||||
len = ba.readInt();
|
||||
pos += 4;
|
||||
a2pal.writeBytes(ba,pos,len);
|
||||
a2pal.position = 0;
|
||||
ie.genericData = {
|
||||
"palette":pal,
|
||||
"avatarPalette1":a1pal,
|
||||
"avatarPalette2":a2pal
|
||||
};
|
||||
dispatchEvent(ie);
|
||||
return;
|
||||
}
|
||||
throw new Error("Got 0 for GetGamePalette request!");
|
||||
}
|
||||
|
||||
private function onResultGetImageData(le:LoaderEvent) : void
|
||||
{
|
||||
var ne:ImageServerEvent = null;
|
||||
var e:ImageServerEvent = new ImageServerEvent(ImageServerEvent.ON_NEW_DATA);
|
||||
e.id = le.entry.id;
|
||||
var o:Object = le.entry.data;
|
||||
if(o == null)
|
||||
{
|
||||
this._imageCacheArray[e.id] = {
|
||||
"id":e.id,
|
||||
"imageData":null,
|
||||
"layer":0,
|
||||
"frames":0
|
||||
};
|
||||
e.success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(o.v != ImageArray.VERSION)
|
||||
{
|
||||
throw new Error("ERROR: Unrecognized version number(" + o.v.toString(16) + ")!");
|
||||
}
|
||||
e.imageData = o;
|
||||
e.layer = this._layerInfo[ImageArrayHelper.layerId(e.id)];
|
||||
e.frames = o.f.length;
|
||||
this._imageCacheArray[e.id] = {
|
||||
"id":e.id,
|
||||
"imageData":o,
|
||||
"layer":e.layer,
|
||||
"frames":e.frames
|
||||
};
|
||||
}
|
||||
this._loaderCacheArray[e.id].l.removeEventListener(LoaderEvent.ON_LOAD_COMPLETE,this.onResultGetImageData);
|
||||
var c:int = int(this._loaderCacheArray[e.id].c);
|
||||
this._loaderCacheArray[e.id] = null;
|
||||
while(c-- > 0)
|
||||
{
|
||||
ne = new ImageServerEvent(ImageServerEvent.ON_NEW_DATA);
|
||||
ne.id = e.id;
|
||||
ne.imageData = e.imageData;
|
||||
ne.layer = e.layer;
|
||||
ne.frames = e.frames;
|
||||
ne.success = e.success;
|
||||
dispatchEvent(ne);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SingletonLock
|
||||
{
|
||||
|
||||
public function SingletonLock()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import com.adobe.crypto.MD5;
|
||||
import com.carlcalderon.arthropod.Debug;
|
||||
import com.sbi.debug.DebugUtility;
|
||||
import flash.net.URLRequest;
|
||||
|
||||
public class LoaderCache
|
||||
{
|
||||
|
||||
public static var cdnSalt:String;
|
||||
|
||||
public static var mainClassNames:Array;
|
||||
|
||||
public static var _contentURL:String = "http://dev-sfs01.smartbombinteractive.com:8008/animal/";
|
||||
|
||||
public static var buildVersion:String = "0";
|
||||
|
||||
public static var deployVersion:String = "0";
|
||||
|
||||
public static var localMode:Boolean = true;
|
||||
|
||||
private static var _clientIp:String = "127.0.0.1";
|
||||
|
||||
private static var _urlIndex:int = 0;
|
||||
|
||||
private var _list:Array = null;
|
||||
|
||||
public function LoaderCache()
|
||||
{
|
||||
super();
|
||||
this._list = new Array();
|
||||
}
|
||||
|
||||
public static function get contentURL() : String
|
||||
{
|
||||
return _contentURL;
|
||||
}
|
||||
|
||||
public static function set contentURL(value:String) : void
|
||||
{
|
||||
var regexp:RegExp = new RegExp("https*://","ig");
|
||||
_contentURL = value.replace(regexp,"");
|
||||
}
|
||||
|
||||
public static function get clientIp() : String
|
||||
{
|
||||
return _clientIp;
|
||||
}
|
||||
|
||||
public static function set clientIp(value:String) : void
|
||||
{
|
||||
_clientIp = value;
|
||||
}
|
||||
|
||||
public static function fetchCDNHash(assetPath:String, cdnRoot:String = "/") : String
|
||||
{
|
||||
var finalHashableString:String = cdnSalt + cdnRoot + assetPath + clientIp;
|
||||
return MD5.hash(finalHashableString);
|
||||
}
|
||||
|
||||
public static function fetchCDNURL(assetPath:String, cdnRoot:String = "/", useDeployVersion:Boolean = true) : String
|
||||
{
|
||||
var cdnURL:String = null;
|
||||
var rootStr:String = cdnRoot;
|
||||
var cdnURLDeployVersionStr:String = "";
|
||||
var deployVersionStr:String = deployVersion;
|
||||
if(deployVersionStr != "0" && useDeployVersion)
|
||||
{
|
||||
cdnURLDeployVersionStr = deployVersionStr + "/";
|
||||
rootStr += cdnURLDeployVersionStr;
|
||||
}
|
||||
var cdnHash:String = fetchCDNHash(assetPath,rootStr);
|
||||
if(useDeployVersion)
|
||||
{
|
||||
cdnURL = "http://" + contentURL + cdnURLDeployVersionStr + assetPath + "?px-hash=" + cdnHash + "&v=" + LoaderCache.buildVersion;
|
||||
}
|
||||
else
|
||||
{
|
||||
cdnURL = "http://" + contentURL + cdnURLDeployVersionStr + assetPath + "?px-hash=" + cdnHash;
|
||||
}
|
||||
Debug.log("CdnURL = " + cdnURL);
|
||||
return cdnURL;
|
||||
}
|
||||
|
||||
public static function fetchCDNURLRequest(assetPath:String, cdnRoot:String = "/", useDeployVersion:Boolean = true) : URLRequest
|
||||
{
|
||||
var cdnURL:String = fetchCDNURL(assetPath,cdnRoot,useDeployVersion);
|
||||
return new URLRequest(cdnURL);
|
||||
}
|
||||
|
||||
public function openFile(swf:String, completeCallback:Function, progressCallback:Function = null, dataFormat:String = "binary") : void
|
||||
{
|
||||
var entry:* = undefined;
|
||||
if(!this.findFile(swf))
|
||||
{
|
||||
entry = this.createLoaderCacheEntry(swf);
|
||||
this._list[swf] = entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUtility.debugTrace("*LoaderCache name collision: " + swf);
|
||||
}
|
||||
this._list[swf].setCompleteCallback(completeCallback);
|
||||
if(progressCallback != null)
|
||||
{
|
||||
this._list[swf].setProgressCallback(progressCallback);
|
||||
}
|
||||
this._list[swf].load(dataFormat);
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
var key:Object = null;
|
||||
for(key in this._list)
|
||||
{
|
||||
this.remove(String(key));
|
||||
}
|
||||
}
|
||||
|
||||
private function findFile(name:String) : Boolean
|
||||
{
|
||||
return this._list[name] == null ? false : true;
|
||||
}
|
||||
|
||||
public function remove(swf:String) : void
|
||||
{
|
||||
this._list[swf].destroy();
|
||||
this._list[swf] = null;
|
||||
}
|
||||
|
||||
private function createLoaderCacheEntry(swf:String) : *
|
||||
{
|
||||
var l:* = undefined;
|
||||
var i:int = swf.lastIndexOf(".");
|
||||
var ext:String = swf.slice(i + 1,swf.length).toLowerCase();
|
||||
switch(ext)
|
||||
{
|
||||
case "swf":
|
||||
case "png":
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
l = new LoaderCacheEntry_Loader(swf);
|
||||
break;
|
||||
default:
|
||||
l = new LoaderCacheEntry_URL(swf);
|
||||
}
|
||||
l.parent = this;
|
||||
return l;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.display.Loader;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
|
||||
public class LoaderCacheEntry_Base extends EventDispatcher
|
||||
{
|
||||
|
||||
protected var _parent:LoaderCache;
|
||||
|
||||
protected var _loader:*;
|
||||
|
||||
protected var _swf:String;
|
||||
|
||||
protected var _isLoaded:Boolean;
|
||||
|
||||
protected var _completeCallback:Function;
|
||||
|
||||
protected var _data:Object;
|
||||
|
||||
protected var _id:*;
|
||||
|
||||
protected var _contentType:int;
|
||||
|
||||
private var _percent:Number;
|
||||
|
||||
private var _err:String;
|
||||
|
||||
private var _progressCallback:Function;
|
||||
|
||||
public function LoaderCacheEntry_Base(swf:String)
|
||||
{
|
||||
super();
|
||||
this._swf = swf;
|
||||
}
|
||||
|
||||
public function set parent(p:LoaderCache) : void
|
||||
{
|
||||
this._parent = p;
|
||||
}
|
||||
|
||||
public function set id(id:*) : void
|
||||
{
|
||||
this._id = id;
|
||||
}
|
||||
|
||||
public function get id() : *
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public function set contentType(ct:int) : void
|
||||
{
|
||||
this._contentType = ct;
|
||||
}
|
||||
|
||||
public function get contentType() : int
|
||||
{
|
||||
return this._contentType;
|
||||
}
|
||||
|
||||
public function get name() : String
|
||||
{
|
||||
return this._swf;
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
}
|
||||
|
||||
public function load(dataFormat:String = "binary", useDeployVersion:Boolean = true) : void
|
||||
{
|
||||
}
|
||||
|
||||
public function setCompleteCallback(completeCallback:Function) : void
|
||||
{
|
||||
if(this._completeCallback != completeCallback)
|
||||
{
|
||||
if(this._completeCallback != null)
|
||||
{
|
||||
removeEventListener(LoaderEvent.ON_LOAD_COMPLETE,this._completeCallback);
|
||||
}
|
||||
addEventListener(LoaderEvent.ON_LOAD_COMPLETE,completeCallback,false,0,true);
|
||||
this._completeCallback = completeCallback;
|
||||
}
|
||||
}
|
||||
|
||||
public function setProgressCallback(progressCallback:Function) : void
|
||||
{
|
||||
if(this._progressCallback != progressCallback)
|
||||
{
|
||||
if(this._progressCallback != null)
|
||||
{
|
||||
removeEventListener(LoaderEvent.ON_LOAD_PROGRESS,this._progressCallback);
|
||||
}
|
||||
addEventListener(LoaderEvent.ON_LOAD_PROGRESS,progressCallback,false,0,true);
|
||||
this._progressCallback = progressCallback;
|
||||
}
|
||||
}
|
||||
|
||||
public function get progress() : Number
|
||||
{
|
||||
return this._percent;
|
||||
}
|
||||
|
||||
public function get loader() : Loader
|
||||
{
|
||||
return this._loader;
|
||||
}
|
||||
|
||||
public function get data() : Object
|
||||
{
|
||||
return this._data;
|
||||
}
|
||||
|
||||
protected function onLoadCompleteEvent() : void
|
||||
{
|
||||
var newEvt:LoaderEvent = new LoaderEvent(LoaderEvent.ON_LOAD_COMPLETE);
|
||||
newEvt.status = true;
|
||||
newEvt.entry = this;
|
||||
dispatchEvent(newEvt);
|
||||
if(Boolean(this._parent))
|
||||
{
|
||||
this._parent.remove(this._swf);
|
||||
}
|
||||
}
|
||||
|
||||
protected function onLoadProgressEvent() : void
|
||||
{
|
||||
var newEvt:LoaderEvent = new LoaderEvent(LoaderEvent.ON_LOAD_PROGRESS);
|
||||
newEvt.status = true;
|
||||
newEvt.entry = this;
|
||||
newEvt.percent = this._percent;
|
||||
dispatchEvent(newEvt);
|
||||
}
|
||||
|
||||
protected function loadProgress(event:ProgressEvent) : void
|
||||
{
|
||||
this._percent = event.bytesLoaded / event.bytesTotal;
|
||||
this._percent = Math.round(this._percent * 100);
|
||||
this.onLoadProgressEvent();
|
||||
}
|
||||
|
||||
protected function ioError(event:IOErrorEvent) : void
|
||||
{
|
||||
var newEvt:LoaderEvent = new LoaderEvent(LoaderEvent.ON_LOAD_COMPLETE);
|
||||
newEvt.status = false;
|
||||
newEvt.entry = this;
|
||||
newEvt.message = event.text;
|
||||
dispatchEvent(newEvt);
|
||||
if(Boolean(this._parent))
|
||||
{
|
||||
this._parent.remove(this._swf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.display.Loader;
|
||||
import flash.display.LoaderInfo;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.net.URLRequest;
|
||||
import flash.system.ApplicationDomain;
|
||||
import flash.system.LoaderContext;
|
||||
import flash.system.SecurityDomain;
|
||||
|
||||
public class LoaderCacheEntry_Loader extends LoaderCacheEntry_Base
|
||||
{
|
||||
|
||||
public function LoaderCacheEntry_Loader(swf:String)
|
||||
{
|
||||
super(swf);
|
||||
_loader = new Loader();
|
||||
_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,loadProgress,false,0,true);
|
||||
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.loadComplete,false,0,true);
|
||||
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioError,false,0,true);
|
||||
}
|
||||
|
||||
override public function destroy() : void
|
||||
{
|
||||
_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,loadProgress);
|
||||
_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,this.loadComplete);
|
||||
_loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,ioError);
|
||||
if(_completeCallback != null)
|
||||
{
|
||||
removeEventListener(LoaderEvent.ON_LOAD_COMPLETE,_completeCallback);
|
||||
_completeCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
override public function load(dataFormat:String = "binary", useDeployVersion:Boolean = true) : void
|
||||
{
|
||||
var request:URLRequest = null;
|
||||
var ldrContext:LoaderContext = null;
|
||||
if(!_isLoaded)
|
||||
{
|
||||
if(LoaderCache.localMode && (_swf.slice(0,7) == "assets/" || _swf.slice(0,6) == "games/" || _swf.indexOf("/") == -1))
|
||||
{
|
||||
request = new URLRequest(_swf);
|
||||
}
|
||||
else
|
||||
{
|
||||
request = LoaderCache.fetchCDNURLRequest(_swf,"/",useDeployVersion);
|
||||
}
|
||||
ldrContext = new LoaderContext(true,ApplicationDomain.currentDomain);
|
||||
if(!LoaderCache.localMode)
|
||||
{
|
||||
ldrContext.securityDomain = SecurityDomain.currentDomain;
|
||||
}
|
||||
_loader.load(request,ldrContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
onLoadCompleteEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private function loadComplete(e:Event) : void
|
||||
{
|
||||
_isLoaded = true;
|
||||
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
|
||||
_data = loaderInfo.content;
|
||||
onLoadCompleteEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLRequest;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class LoaderCacheEntry_URL extends LoaderCacheEntry_Base
|
||||
{
|
||||
|
||||
private var _isObj:Boolean;
|
||||
|
||||
public function LoaderCacheEntry_URL(swf:String, isObj:Boolean = true)
|
||||
{
|
||||
super(swf);
|
||||
this._isObj = isObj;
|
||||
_loader = new URLLoader();
|
||||
_loader.addEventListener(ProgressEvent.PROGRESS,loadProgress,false,0,true);
|
||||
_loader.addEventListener(Event.COMPLETE,this.loadComplete,false,0,true);
|
||||
_loader.addEventListener(IOErrorEvent.IO_ERROR,ioError,false,0,true);
|
||||
}
|
||||
|
||||
override public function destroy() : void
|
||||
{
|
||||
_loader.removeEventListener(ProgressEvent.PROGRESS,loadProgress);
|
||||
_loader.removeEventListener(Event.COMPLETE,this.loadComplete);
|
||||
_loader.removeEventListener(IOErrorEvent.IO_ERROR,ioError);
|
||||
if(_completeCallback != null)
|
||||
{
|
||||
removeEventListener(LoaderEvent.ON_LOAD_COMPLETE,_completeCallback);
|
||||
_completeCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
override public function load(dataFormat:String = "binary", useDeployVersion:Boolean = true) : void
|
||||
{
|
||||
var request:URLRequest = null;
|
||||
if(!_isLoaded)
|
||||
{
|
||||
request = LoaderCache.fetchCDNURLRequest(_swf,"/",useDeployVersion);
|
||||
_loader.dataFormat = dataFormat;
|
||||
trace("LoaderCacheEntry_URL - URLLoader.load being called for cdnURL:" + request.url + " dataFormat:" + dataFormat);
|
||||
_loader.load(request);
|
||||
}
|
||||
else
|
||||
{
|
||||
onLoadCompleteEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private function loadComplete(e:Event) : void
|
||||
{
|
||||
var ba:ByteArray = null;
|
||||
var o:Object = null;
|
||||
_isLoaded = true;
|
||||
_data = _loader.data;
|
||||
if(_data is ByteArray)
|
||||
{
|
||||
ba = _loader.data as ByteArray;
|
||||
try
|
||||
{
|
||||
ba.uncompress();
|
||||
}
|
||||
catch(err:Error)
|
||||
{
|
||||
}
|
||||
ba.position = 0;
|
||||
if(this._isObj)
|
||||
{
|
||||
o = ba.readObject();
|
||||
if(ba.bytesAvailable == 0)
|
||||
{
|
||||
_data = o;
|
||||
}
|
||||
else
|
||||
{
|
||||
ba.position = 0;
|
||||
_data = ba;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_data = ba;
|
||||
}
|
||||
}
|
||||
onLoadCompleteEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class LoaderEvent extends Event
|
||||
{
|
||||
|
||||
public static const ON_LOAD_COMPLETE:String = "OnLoadComplete";
|
||||
|
||||
public static const ON_LOAD_PROGRESS:String = "OnLoadProgress";
|
||||
|
||||
public var status:Boolean;
|
||||
|
||||
public var entry:LoaderCacheEntry_Base;
|
||||
|
||||
public var message:String;
|
||||
|
||||
public var percent:Number;
|
||||
|
||||
public function LoaderEvent(type:String)
|
||||
{
|
||||
super(type);
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new LoaderEvent(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import com.sbi.debug.DebugUtility;
|
||||
|
||||
public class ResourceStack
|
||||
{
|
||||
|
||||
private var _stack:Array;
|
||||
|
||||
private var _callback:Function;
|
||||
|
||||
private var _path:String;
|
||||
|
||||
private var _openFile:Function;
|
||||
|
||||
public function ResourceStack(initPath:String, initOpenFile:Function)
|
||||
{
|
||||
super();
|
||||
this._path = initPath;
|
||||
this._openFile = initOpenFile;
|
||||
this._stack = new Array();
|
||||
}
|
||||
|
||||
public function pushFile(file:String, isBlocking:Boolean = false) : void
|
||||
{
|
||||
this._stack.push({
|
||||
"type":"file",
|
||||
"data":file,
|
||||
"isBlocking":isBlocking,
|
||||
"inProgress":false
|
||||
});
|
||||
}
|
||||
|
||||
public function pushClass(classRef:IResourceStackable, isBlocking:Boolean = false) : void
|
||||
{
|
||||
this._stack.push({
|
||||
"type":"class",
|
||||
"data":classRef,
|
||||
"isBlocking":isBlocking,
|
||||
"inProgress":false
|
||||
});
|
||||
}
|
||||
|
||||
public function start(callback:Function) : void
|
||||
{
|
||||
this._callback = callback;
|
||||
this.fifo();
|
||||
}
|
||||
|
||||
private function fifo() : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var o:Object = null;
|
||||
var len:int = int(this._stack.length);
|
||||
DebugUtility.debugTrace("ResourceStack fifo len:" + len);
|
||||
if(!len)
|
||||
{
|
||||
DebugUtility.debugTrace("ResourceStack _callback:" + this._callback);
|
||||
if(this._callback != null)
|
||||
{
|
||||
this._callback();
|
||||
this._callback = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 0; i < len; i++)
|
||||
{
|
||||
o = this._stack[i];
|
||||
DebugUtility.debugTrace("ResourceStack fifo next - o:" + o + " o.inProgress:" + o.inProgress + " o.type:" + o.type + " o.data:" + o.data + " o.isBlocking:" + o.isBlocking);
|
||||
if(!o.inProgress)
|
||||
{
|
||||
o.inProgress = true;
|
||||
switch(o.type)
|
||||
{
|
||||
case "file":
|
||||
this.loadFile(o.data);
|
||||
break;
|
||||
case "class":
|
||||
o.data.init(this.onInitClassComplete);
|
||||
}
|
||||
i = -1;
|
||||
len = int(this._stack.length);
|
||||
}
|
||||
else if(Boolean(o.isBlocking))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function loadFile(loadTarget:String) : void
|
||||
{
|
||||
var target:String = this._path + loadTarget;
|
||||
this._openFile(target,this.onLoadComplete,this.onLoadProgress);
|
||||
}
|
||||
|
||||
private function onLoadComplete(e:LoaderEvent) : void
|
||||
{
|
||||
if(e.status)
|
||||
{
|
||||
DebugUtility.debugTrace("ResourceStack onLoadComplete e:" + e + " name:" + e.entry.name);
|
||||
this.removeResource("file",e.entry.name);
|
||||
this.fifo();
|
||||
return;
|
||||
}
|
||||
throw new Error("could not load required resource!!! msg:" + e.message);
|
||||
}
|
||||
|
||||
private function onLoadProgress(e:LoaderEvent) : void
|
||||
{
|
||||
}
|
||||
|
||||
private function onInitClassComplete(classRef:IResourceStackable) : void
|
||||
{
|
||||
this.removeResource("class",classRef);
|
||||
this.fifo();
|
||||
}
|
||||
|
||||
private function removeResource(type:String, data:*) : void
|
||||
{
|
||||
var s:Object = null;
|
||||
var len:int = int(this._stack.length);
|
||||
for(var i:int = 0; i < len; i++)
|
||||
{
|
||||
s = this._stack[i];
|
||||
if(s.type == type && s.data == data)
|
||||
{
|
||||
this._stack.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,350 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Loader;
|
||||
import flash.display.LoaderInfo;
|
||||
import flash.display.MovieClip;
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.geom.Point;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.system.ApplicationDomain;
|
||||
import flash.system.LoaderContext;
|
||||
import flash.utils.Dictionary;
|
||||
import localization.LocalizationManager;
|
||||
|
||||
public class SceneLoader extends EventDispatcher
|
||||
{
|
||||
|
||||
public static const LOAD_STATE_NOTLOADED:int = 0;
|
||||
|
||||
public static const LOAD_STATE_LOADING:int = 1;
|
||||
|
||||
public static const LOAD_STATE_LOADED:int = 2;
|
||||
|
||||
private var _offset:Point;
|
||||
|
||||
private var _scene:Object;
|
||||
|
||||
private var _loaderCount:int;
|
||||
|
||||
private var _loader:Array;
|
||||
|
||||
private var _loadedAssets:Dictionary;
|
||||
|
||||
private var _loaderLUT:Dictionary;
|
||||
|
||||
private var _initCount:int;
|
||||
|
||||
private var _loadProgressCallback:Function;
|
||||
|
||||
public var _useDynamicLoading:Boolean;
|
||||
|
||||
public function SceneLoader(loadProgressCallback:Function = null)
|
||||
{
|
||||
super();
|
||||
this._loader = new Array();
|
||||
this._loadProgressCallback = loadProgressCallback;
|
||||
}
|
||||
|
||||
public function getOffset(stage:DisplayObject) : Point
|
||||
{
|
||||
var o:Object = null;
|
||||
var s:Loader = null;
|
||||
var rect:Rectangle = null;
|
||||
var layers:Array = this.getActorList("ActorLayer");
|
||||
for each(o in layers)
|
||||
{
|
||||
s = o.s;
|
||||
rect = s.getBounds(stage);
|
||||
if(rect.x < this._offset.x)
|
||||
{
|
||||
this._offset.x = rect.x;
|
||||
}
|
||||
if(rect.y < this._offset.y)
|
||||
{
|
||||
this._offset.y = rect.y;
|
||||
}
|
||||
}
|
||||
return this._offset;
|
||||
}
|
||||
|
||||
public function get isValid() : Boolean
|
||||
{
|
||||
return this._scene != null;
|
||||
}
|
||||
|
||||
public function get sceneObject() : Object
|
||||
{
|
||||
return this._scene;
|
||||
}
|
||||
|
||||
public function setScene(scene:Object, forceStaticLoad:Boolean = false) : void
|
||||
{
|
||||
this.release();
|
||||
this._scene = scene;
|
||||
this._loadedAssets = new Dictionary();
|
||||
this._loaderLUT = new Dictionary();
|
||||
if(Boolean(scene))
|
||||
{
|
||||
this.loadLayers(forceStaticLoad);
|
||||
}
|
||||
}
|
||||
|
||||
public function getActorList(name:String) : Array
|
||||
{
|
||||
return this._scene.actors[name];
|
||||
}
|
||||
|
||||
public function getLayer(name:String) : Object
|
||||
{
|
||||
return this.findLayer(name);
|
||||
}
|
||||
|
||||
public function cloneAsset(name:String) : Object
|
||||
{
|
||||
var loader:Loader = null;
|
||||
var o:Object = this.findLayer(name);
|
||||
if(Boolean(o))
|
||||
{
|
||||
loader = this.newAsset(o.assetName);
|
||||
loader.x = o.x;
|
||||
loader.y = o.y;
|
||||
o.loader = loader;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
public function release() : void
|
||||
{
|
||||
var l:Loader = null;
|
||||
while(Boolean(this._loader.length))
|
||||
{
|
||||
l = this._loader.pop();
|
||||
l.unloadAndStop();
|
||||
}
|
||||
}
|
||||
|
||||
public function releaseCloneAsset(l:Loader) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var le:Loader = null;
|
||||
while(i < this._loader.length)
|
||||
{
|
||||
le = this._loader[i];
|
||||
if(le == l)
|
||||
{
|
||||
l.unloadAndStop();
|
||||
this._loader.splice(i,1);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public function forceLoadComplete() : void
|
||||
{
|
||||
this._loadProgressCallback(false);
|
||||
}
|
||||
|
||||
private function findLayer(name:String) : Object
|
||||
{
|
||||
var o:Object = null;
|
||||
var i:int = 0;
|
||||
var a:Array = this.getActorList("ActorLayer");
|
||||
name = name.toLowerCase();
|
||||
for(i = 0; i < a.length; i++)
|
||||
{
|
||||
if(a[i].name == name)
|
||||
{
|
||||
o = new Object();
|
||||
o.assetName = a[i].assetName;
|
||||
o.loader = a[i].s;
|
||||
o.height = a[i].s.height;
|
||||
o.width = a[i].s.width;
|
||||
o.x = a[i].s.x;
|
||||
o.y = a[i].s.y;
|
||||
o.flip = a[i].flip;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(o == null)
|
||||
{
|
||||
trace("Layer Not Found: " + name);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
private function newAsset(name:String) : Loader
|
||||
{
|
||||
var l:Loader = null;
|
||||
var i:int = 0;
|
||||
name = name.toLowerCase();
|
||||
for(var a:Array = this._scene.assets; i < a.length; )
|
||||
{
|
||||
if(a[i].name.toLowerCase() == name)
|
||||
{
|
||||
l = new Loader();
|
||||
l.loadBytes(a[i].ba);
|
||||
l.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onNewLoaderComplete);
|
||||
l.cacheAsBitmap = true;
|
||||
this._loader.push(l);
|
||||
return l;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
private function onNewLoaderComplete(e:Event) : void
|
||||
{
|
||||
var l:LoaderInfo = e.target as LoaderInfo;
|
||||
l.removeEventListener(Event.COMPLETE,this.onLoaderComplete);
|
||||
if(l.content is MovieClip && MovieClip(l.content).totalFrames > 1)
|
||||
{
|
||||
l.content.cacheAsBitmap = false;
|
||||
}
|
||||
dispatchEvent(e);
|
||||
}
|
||||
|
||||
public function loadLayer(o:Object) : void
|
||||
{
|
||||
o.loaded = LOAD_STATE_LOADING;
|
||||
this._loaderLUT[o.s] = o;
|
||||
var l:Loader = this.loadAsset(o.assetName,o.s);
|
||||
++this._initCount;
|
||||
}
|
||||
|
||||
public function isValidDynamicAsset(o:Object) : Boolean
|
||||
{
|
||||
return o.name == "" && o.typeIndex != 1 && o.typeIndex != 2 && o.dx == 1 && o.dy == 1;
|
||||
}
|
||||
|
||||
private function loadLayers(forceStaticLoad:Boolean = false) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var o:Object = null;
|
||||
var l:Loader = null;
|
||||
this._offset = new Point(9999999,9999999);
|
||||
var a:Array = this.getActorList("ActorLayer");
|
||||
this._loaderCount = a.length;
|
||||
this._initCount = 0;
|
||||
if(Boolean(a.length > 0) && Boolean(a[0].hasOwnProperty("top")) && !forceStaticLoad)
|
||||
{
|
||||
this._useDynamicLoading = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._useDynamicLoading = false;
|
||||
}
|
||||
var namedAssetsLoading:Boolean = false;
|
||||
for(i = 0; i < a.length; i++)
|
||||
{
|
||||
o = a[i];
|
||||
o.dx = o.scrollX;
|
||||
o.dy = o.scrollY;
|
||||
if(this._useDynamicLoading)
|
||||
{
|
||||
o.offsetX = o.left - o.x;
|
||||
o.offsetY = o.top - o.y;
|
||||
if(Boolean(o.flip & 1))
|
||||
{
|
||||
o.offsetX -= o.width;
|
||||
}
|
||||
if(Boolean(o.flip & 2))
|
||||
{
|
||||
o.offsetY -= o.height;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
o.offsetX = 0;
|
||||
o.offsetY = 0;
|
||||
}
|
||||
if(this._useDynamicLoading && namedAssetsLoading && this.isValidDynamicAsset(o))
|
||||
{
|
||||
--this._loaderCount;
|
||||
l = new Loader();
|
||||
o.loaded = LOAD_STATE_NOTLOADED;
|
||||
}
|
||||
else
|
||||
{
|
||||
o.loaded = LOAD_STATE_LOADING;
|
||||
this._loadedAssets[o.assetName] = l = this.loadAsset(o.assetName);
|
||||
namedAssetsLoading = true;
|
||||
}
|
||||
o.s = l;
|
||||
this._loaderLUT[l] = o;
|
||||
l.x = Math.round(o.x);
|
||||
l.y = Math.round(o.y);
|
||||
l.rotation = o.rot;
|
||||
l.scaleX = o.scaleX;
|
||||
l.scaleY = o.scaleY;
|
||||
}
|
||||
}
|
||||
|
||||
private function loadAsset(name:String, loader:Loader = null) : Loader
|
||||
{
|
||||
var i:int = 0;
|
||||
var ldrContext:LoaderContext = null;
|
||||
var l:Loader = loader;
|
||||
name = name.toLowerCase();
|
||||
for(var a:Array = this._scene.assets; i < a.length; )
|
||||
{
|
||||
if(a[i].name.toLowerCase() == name)
|
||||
{
|
||||
if(l == null)
|
||||
{
|
||||
l = new Loader();
|
||||
}
|
||||
if(Boolean(a[i].ba))
|
||||
{
|
||||
ldrContext = new LoaderContext(false,ApplicationDomain.currentDomain);
|
||||
l.loadBytes(a[i].ba,ldrContext);
|
||||
l.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onLoaderComplete);
|
||||
l.cacheAsBitmap = true;
|
||||
this._loader.push(l);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
private function onLoaderComplete(e:Event) : void
|
||||
{
|
||||
var l:LoaderInfo = e.target as LoaderInfo;
|
||||
l.removeEventListener(Event.COMPLETE,this.onLoaderComplete);
|
||||
if(l.content is MovieClip)
|
||||
{
|
||||
LocalizationManager.findAllTextfields(l.content);
|
||||
if(MovieClip(l.content).totalFrames > 1)
|
||||
{
|
||||
l.content.cacheAsBitmap = false;
|
||||
}
|
||||
}
|
||||
--this._loaderCount;
|
||||
this._loaderLUT[l.loader].loaded = LOAD_STATE_LOADED;
|
||||
if(this._initCount > 0)
|
||||
{
|
||||
--this._initCount;
|
||||
if(this._initCount == 0)
|
||||
{
|
||||
this._loadProgressCallback(false);
|
||||
}
|
||||
}
|
||||
if(this._loaderCount == 0)
|
||||
{
|
||||
this.allLoadingComplete();
|
||||
}
|
||||
}
|
||||
|
||||
private function allLoadingComplete() : void
|
||||
{
|
||||
var e:Event = new Event(Event.COMPLETE);
|
||||
dispatchEvent(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user