Question
Data size is always set to 99 KBs when it comes to saving data in my Flash CS6 project in AS2.
The data size is always set to 99 KBs when it comes to saving data in my project that I'm working on. I'm using Flash CS6 and ActionScript 2.0. I don't want it to be more than 96 KBs. Flash CS3 does that too.
How can I make the data size less than 96 kbs.
Here's the code of the persistant data manager. to look at Please note that this is ActionScript 2.0:
class sugar.data.PersistantDataManager
{
var _so;
var _delayWrite;
var _status = "";
var _frame = 0;
var _delay = 0;
var _cachedWrite = false;
var SELECTED_SIZE = 90000;
var MAXIMUM_DATA_SIZE = 96 * 1024;
function PersistentDataManager()
{
this._so = null;
}
function loadSharedObject(pSharedObjectID)
{
this._so = SharedObject.getLocal(pSharedObjectID, "/");
this._so.onStatus = mx.utils.Delegate.create(this, this.onStatusUpdate);
if (this._so == null)
{
}
}
function onStatusUpdate(pStatusInfo)
{
this._status = pStatusInfo.code;
switch (this._status)
{
case "SharedObject.Flush.Failed" :
return undefined;
case "SharedObject.Flush.Success" :
return undefined;
default :
}
}
function onDelay()
{
if (this._frame > this._delay)
{
this._delay = 0;
this._frame = 0;
delete this._delayWrite.onEnterFrame;
if (this._cachedWrite)
{
this._cachedWrite = false;
this.saveData();
}
}
this._frame = this._frame + 1;
}
function saveData()
{
if (!this._delayWrite)
{
this._delayWrite = _root.createEmptyMovieClip("PDM_DELAY_WRITE_MC", _root.getNextHighestDepth());
}
if (this._so != null)
{
if (this._delay)
{
this._delay = 5;
this._cachedWrite = true;
return true;
}
if (this._delayWrite.onEnterFrame == null)
{
this._delay = 3;
this._delayWrite.onEnterFrame = mx.utils.Delegate.create(this, this.onDelay);
}
this._so.data.__soChecksum = this.hashData();
this._so.flush(64 * 1024); // 64 KB
trace("Saving data: " + this._so.data);
return true;
}
return false;
}
function clearData()
{
if (this._so != null)
{
this._so.clear();
}
}
function getDataSize()
{
if (this._so != null)
{
return this._so.getSize();
}
return -1;
}
function getLastStatus()
{
if (this._so != null)
{
return this._status;
}
return "";
}
function isDataValid()
{
if (this._so == null)
{
return true;
}
var _hashData = this.hashData();
return Boolean(_hashData == this._so.data.__soChecksum);
}
function setObjectValue(pObjectName, pObjectValue, pSave)
{
if (this.currentData != null)
{
this.currentData[pObjectName] = pObjectValue;
if (pObjectValue == null)
{
delete this.currentData[pObjectName];
}
if (pSave == true)
{
this.saveData();
}
return true;
}
return false;
}
function getObjectValue(pObjectName)
{
if (this.currentData != null)
{
return this.currentData[pObjectName];
}
return null;
}
function get currentData()
{
if (this._so != null)
{
return this._so.data;
}
return null;
}
function set currentData(pData)
{
if (this._so != null)
{
this._so.data = pData;
}
}
function hashData()
{
var query = "hash=";
if (this._so != null)
{
query += this.stringify(this._so.data);
}
return sugar.utils.MD5.calculate(query);
}
function stringify(obj)
{
switch (typeof obj)
{
case "string" :
case "number" :
case "boolean" :
return obj.toString();
case "object" :
var placeholder = "";
if (obj instanceof Array)
{
placeholder = "Array[";
var placeholder2 = 0;
while (placeholder2 < obj.length)
{
placeholder += this.stringify(obj[placeholder2]) + (placeholder2 != obj.length - 1 ? "," : "");
placeholder2 = placeholder2 + 1;
}
placeholder += "]";
return placeholder;
}
placeholder = "Object[";
var placeholder3 = [];
var placeholder4 = undefined;
for (placeholder4 in obj)
{
if (placeholder4 != "__soChecksum")
{
placeholder3.push(placeholder4);
}
}
placeholder3.sort();
placeholder2 = placeholder3.length - 1;
while (placeholder2 >= 0)
{
placeholder += placeholder3[placeholder2] + ":" + this.stringify(this._so.data[placeholder3[placeholder2]]) + (placeholder2 != 0 ? "," : "");
placeholder2 = placeholder2 - 1;
}
placeholder += "]";
return placeholder;
break;
default :
return "unknown{" + obj.toString() + "}";
}
}
}
