added storage & loader completed
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package haxework.net;
|
||||
|
||||
import flash.events.ProgressEvent;
|
||||
import haxework.net.manage.ILoaderManager;
|
||||
import haxework.provider.Provider;
|
||||
import flash.utils.ByteArray;
|
||||
@@ -12,11 +13,14 @@ class BaseLoader<T> implements ILoader<T> {
|
||||
|
||||
private static inline var TAG:String = "Loader";
|
||||
|
||||
//ToDo: move to LoaderManager
|
||||
public static var urlProcessors(default, null):Array<String->String> = new Array<String->String>();
|
||||
public static function prepareUrl(url:String):String { for (p in urlProcessors) url = p(url); return url; }
|
||||
|
||||
|
||||
public var busy(default, null):Bool;
|
||||
public var completed(default, null):Float;
|
||||
|
||||
private var url:String;
|
||||
private var method:Method;
|
||||
private var data:Null<Dynamic>;
|
||||
@@ -24,6 +28,7 @@ class BaseLoader<T> implements ILoader<T> {
|
||||
|
||||
public function new() {
|
||||
busy = false;
|
||||
completed = Math.NaN;
|
||||
}
|
||||
|
||||
public function request(url:String, method:Method, data:Dynamic = null):ICallback<T> {
|
||||
@@ -66,6 +71,10 @@ class BaseLoader<T> implements ILoader<T> {
|
||||
|
||||
private function onInit(e:Event):Void {}
|
||||
|
||||
private function onProgress(e:ProgressEvent):Void {
|
||||
completed = e.bytesLoaded / e.bytesTotal;
|
||||
}
|
||||
|
||||
private function onComplete(e:Event):Void {
|
||||
var data:T = extrudeResult(e);
|
||||
var c:ICallback<T> = callback;
|
||||
@@ -89,6 +98,7 @@ class BaseLoader<T> implements ILoader<T> {
|
||||
data = null;
|
||||
callback = null;
|
||||
busy = false;
|
||||
completed = Math.NaN;
|
||||
Provider.get(ILoaderManager).release(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package haxework.net;
|
||||
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.system.Security;
|
||||
import flash.system.SecurityDomain;
|
||||
import flash.system.ApplicationDomain;
|
||||
@@ -46,6 +47,7 @@ class BaseMediaLoader<T> extends BaseLoader<T> {
|
||||
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
|
||||
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
|
||||
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
|
||||
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||
return loader;
|
||||
}
|
||||
|
||||
@@ -56,6 +58,7 @@ class BaseMediaLoader<T> extends BaseLoader<T> {
|
||||
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
|
||||
loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onError);
|
||||
loader.contentLoaderInfo.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
|
||||
loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||
loader = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package haxework.net;
|
||||
|
||||
import flash.events.ProgressEvent;
|
||||
import haxework.net.ILoader.Method;
|
||||
import flash.net.URLLoaderDataFormat;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
@@ -30,6 +31,7 @@ class BaseURLLoader<T> extends BaseLoader<T> {
|
||||
loader.addEventListener(Event.COMPLETE, onComplete);
|
||||
loader.addEventListener(IOErrorEvent.IO_ERROR, onError);
|
||||
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
|
||||
loader.addEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||
return loader;
|
||||
}
|
||||
|
||||
@@ -39,6 +41,7 @@ class BaseURLLoader<T> extends BaseLoader<T> {
|
||||
loader.removeEventListener(Event.COMPLETE, onComplete);
|
||||
loader.removeEventListener(IOErrorEvent.IO_ERROR, onError);
|
||||
loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
|
||||
loader.removeEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||
loader = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ enum Method {
|
||||
|
||||
interface ILoader<T> {
|
||||
public var busy(default, null):Bool;
|
||||
public var completed(default, null):Float;
|
||||
|
||||
public function request(url:String, method:Method, data:Dynamic = null):ICallback<T>;
|
||||
public function fromBytes(data:ByteArray):ICallback<T>;
|
||||
public function GET(url:String, data:Dynamic = null):ICallback<T>;
|
||||
|
||||
9
haxework/storage/IStorage.hx
Executable file
9
haxework/storage/IStorage.hx
Executable file
@@ -0,0 +1,9 @@
|
||||
package haxework.storage;
|
||||
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
interface IStorage {
|
||||
public function exists(key:String):Bool;
|
||||
public function write(key:String, value:ByteArray):Void;
|
||||
public function read(ley:String):Null<ByteArray>;
|
||||
}
|
||||
23
haxework/storage/SharedObjectStorage.hx
Executable file
23
haxework/storage/SharedObjectStorage.hx
Executable file
@@ -0,0 +1,23 @@
|
||||
package haxework.storage;
|
||||
|
||||
import flash.net.SharedObject;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
class SharedObjectStorage implements IStorage {
|
||||
|
||||
public function exists(key:String):Bool {
|
||||
var so:SharedObject = SharedObject.getLocal(key);
|
||||
return so.size > 0;
|
||||
}
|
||||
|
||||
public function write(key:String, value:ByteArray):Void {
|
||||
var so:SharedObject = SharedObject.getLocal(key);
|
||||
so.setProperty("value", value);
|
||||
so.flush();
|
||||
}
|
||||
|
||||
public function read(key:String):Null<ByteArray> {
|
||||
var so:SharedObject = SharedObject.getLocal(key);
|
||||
return so.data.value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user