Flash / Flex / ActionScript/Development/SharedObject
OverflowTest
package
{
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.net.SharedObject;
import flash.net.SharedObjectFlushStatus;
public class Main extends Sprite
{
protected var so:SharedObject = SharedObject.getLocal("storage");
public function Main(){
//request 1 MB up front
if (so.flush(1024 * 1024) == SharedObjectFlushStatus.PENDING)
{
so.addEventListener(NetStatusEvent.NET_STATUS, onUserAction);
trace("User approval pending...");
}
}
public function onUserAction(event:NetStatusEvent):void{
so.removeEventListener(NetStatusEvent.NET_STATUS, onUserAction);
switch (event.info.code)
{
case "SharedObject.Flush.Success":
trace("Accepted");
break;
case "SharedObject.Flush.Failed":
trace("Denied");
//do error recovery
break;
}
}
}
}
package{
import flash.display.Sprite;
import flash.net.SharedObject;
public class Main extends Sprite{
public function Main(){
var hiscores:SharedObject = SharedObject.getLocal("hiscores");
hiscores.data.highest = 999999;
if (hiscores.data.scores){
for (var i:int = 0; i < hiscores.data.scores.length; i++){
trace(i + ": "+ hiscores.data.scores[i]);
}
}
}
}
}