import DojoExternalInterface; class Storage { public static var SUCCESS = "success"; public static var FAILED = "failed"; public static var PENDING = "pending"; // Wait the following number of milliseconds before flushing public static var FLUSH_DELAY_DEFAULT = 500; public var flush_delay; public var so; public var timer; private var _NAMESPACE_KEY = "allNamespaces"; public function Storage(){ flush_delay = Storage.FLUSH_DELAY_DEFAULT; //getURL("javascript:console.debug('FLASH:Storage constructor')"); DojoExternalInterface.initialize(); DojoExternalInterface.addCallback("put", this, put); DojoExternalInterface.addCallback("putMultiple", this, putMultiple); DojoExternalInterface.addCallback("get", this, get); DojoExternalInterface.addCallback("getMultiple", this, getMultiple); DojoExternalInterface.addCallback("showSettings", this, showSettings); DojoExternalInterface.addCallback("clear", this, clear); DojoExternalInterface.addCallback("getKeys", this, getKeys); DojoExternalInterface.addCallback("getNamespaces", this, getNamespaces); DojoExternalInterface.addCallback("remove", this, remove); DojoExternalInterface.addCallback("removeMultiple", this, removeMultiple); DojoExternalInterface.addCallback("flush", this, flush); DojoExternalInterface.addCallback("setFlushDelay", this, setFlushDelay); DojoExternalInterface.addCallback("getFlushDelay", this, getFlushDelay); DojoExternalInterface.loaded(); // preload the System Settings finished button movie for offline // access so it is in the cache _root.createEmptyMovieClip("_settingsBackground", 1); // getURL("javascript:alert('"+DojoExternalInterface.dojoPath+"');"); _root._settingsBackground.loadMovie(DojoExternalInterface.dojoPath + "storage_dialog.swf"); } // Set a new value for the flush delay timer. // Possible values: // 0 : Perform the flush synchronously after each "put" request // > 0 : Wait until 'newDelay' ms have passed without any "put" request to flush // -1 : Do not automatically flush public function setFlushDelay(newDelay){ flush_delay = Number(newDelay); } public function getFlushDelay(){ return String(flush_delay); } public function flush(namespace){ if(timer){ _global.clearTimeout(timer); delete timer; } var so = SharedObject.getLocal(namespace); //var st = (new Date()).getTime(); var flushResults = so.flush(); //var end = (new Date()).getTime(); //getURL("javascript:dojo.debug('FLASH: flush - not a word game - took " + (end - st) + "ms')"); // return results of this command to JavaScript var statusResults; if(flushResults == true){ statusResults = Storage.SUCCESS; }else if(flushResults == "pending"){ statusResults = Storage.PENDING; }else{ statusResults = Storage.FAILED; } DojoExternalInterface.call("dojox.storage._onStatus", null, statusResults, null); } // FIXME: This code has gotten ugly -- refactor public function put(keyName, keyValue, namespace){ // Get the SharedObject for these values and save it so = SharedObject.getLocal(namespace); // Save the key and value so.data[keyName] = keyValue; // Do all the flush/no-flush stuff var keyNames = new Array(); keyNames[0] = keyName; postWrite( so, keyNames, namespace); } public function putMultiple(metaKey, metaValue, metaLengths, namespace){ // Get the SharedObject for these values and save it so = SharedObject.getLocal(namespace); // Create array of keys and value lengths var keys = metaKey.split(","); var lengths = metaLengths.split(","); // Loop through the array and write the values for(var i=0;i 0){ timer = _global.setTimeout( flush, flush_delay, namespace); // With a flush_delay value of 0, execute the flush request synchronously }else if(flush_delay == 0){ //getURL("javascript:dojo.debug('FLASH: calling flush now')"); flush(namespace); } // Otherwise just don't flush - will be probably be flushed manually } public function get(keyName, namespace){ // Get the SharedObject for these values and save it so = SharedObject.getLocal(namespace); var results = so.data[keyName]; return results; } // Returns an array with the contents of each key value on the metaKeys array public function getMultiple(metaKeys, namespace){ // get the storage object so = SharedObject.getLocal(namespace); // Create array of keys to read var keys = metaKeys.split(","); var results = new Array(); // Read from storage into results array for(var i=0;i