Greets.
I thought some of u would probably get into it. This is a rough copy of my solution to ‘traffic saving’ + duplicate content.
The idea is pretty simple - extend the loader + after Event.COMPLETE event just record the bytes of the content to a static/singleton (as u wish) manager class. After u can freely grab those bytes from the buffer and create a nice & full copy of the object (no matter image/swf).
The manager
package
{
import flash.utils.ByteArray;
public class LoaderManager
{
private static var DATA:Object = {};
public static function setData(id:int, data:ByteArray):void
{
LoaderManager.DATA[id] = data;
}
public static function getData(id:int):ByteArray
{
if(LoaderManager.DATA[id])
return LoaderManager.DATA[id];
else
return null;
}
}
}
The ALoader
package
{
import flash.display.Loader;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.utils.ByteArray;
import flash.events.Event;
import LoaderManager;
public class ALoader extends Loader
{
private var _useManager:Boolean;
private var _id:int;
public function ALoader(useManager:Boolean = false, id:int = -1)
{
this._useManager = useManager;
this._id = id;
super();
}
public override function load(request:URLRequest, context:LoaderContext = null):void
{
if(_useManager)
{
var bytes:ByteArray = LoaderManager.getData(_id);
if(bytes)
{
trace("Yes! Traffic & time economy. Got the content from buffer");
super.loadBytes(bytes);
}else{
super.contentLoaderInfo.addEventListener(Event.COMPLETE, dataLoaded);
super.load(request, context);
}
}else{
super.load(request, context);
}
}
private function dataLoaded(event:Event):void
{
//the magic
LoaderManager.setData(_id, super.contentLoaderInfo.bytes);
}
}
}
Sorry, no comments in code - it’s just a working sketch (writing from my mobile)
Hope this helps anyone. :hugegrin: