I found a way to at least estimate the size of an object before sending it to LocalConnection by creating a temporary SharedObject with data. Since SharedObject is not written to disk, it works even if local storage is not allowed.
Here is the function I'm going to use to determine the size:
public static function getObjectSize(o:Object):Number {
var so:SharedObject = SharedObject.getLocal("__getObjectSizeHelper");
so.data.o = o;
var size:Number = so.getSize();
so.clear();
return size;
}
, , . , ( 100%, , , , , ). , . , . , , ( , 1 , 2 3).
.
, , :
public static function isTooBigForLC(o:Object):Boolean {
return getObjectSize(o) > 35000;
}
public static function splitArrayForLC(a:Array):Array {
if (!isTooBigForLC(a)) { return [a]; }
if (a.length <= 1) {
LOG.warn("individual object is too big for LocalConnection! Skipping");
return [];
}
var mid:Number = Math.floor(a.length / 2);
var left:Array = splitArrayForLC(a.slice(0, mid));
var right:Array = splitArrayForLC(a.slice(mid));
return left.concat(right);
}
, , "" . .
( ) :
http://gist.github.com/224258