Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex: How to detect if user has blocked shared object from writing

Simple question is, how do i detect in actionscript if user have blocked from writing data to shared object?

sharedObj = SharedObject.getLocal("rememberme");

This return always shared object but it's size is 0, even I have blocked shared object.

When I'm trying to save data to shared object and flush it, it throws me an error, because writing is blocked. So what would be the right way check if writing to shared object is disabled?

Error: Error #2130: Unable to flush SharedObject.
like image 208
Jarno Lahtinen Avatar asked Aug 31 '11 06:08

Jarno Lahtinen


1 Answers

var my_so:SharedObject = SharedObject.getLocal("mySpace");
var flushStatus:String = null;
try {
    flushStatus = my_so.flush();
} catch (error:Error) {
    trace("Error...Could not write SharedObject to disk\n");
}
if (flushStatus != null) {
    switch (flushStatus) {
        case SharedObjectFlushStatus.PENDING :
            trace("Requesting permission to save object...\n");
            my_so.addEventListener(NetStatusEvent.NET_STATUS, onFlushStatus);
            break;
        case SharedObjectFlushStatus.FLUSHED :
            trace("Value flushed to disk.\n");
            break;
    }
}
function onFlushStatus(event:NetStatusEvent):void {
    trace("User closed permission dialog...\n");
    switch (event.info.code) {
        case "SharedObject.Flush.Success" :
            trace("User granted permission -- value saved.\n");
            break;
        case "SharedObject.Flush.Failed" :
            trace("User denied permission -- value not saved.\n");
            break;
    }
my_so.removeEventListener(NetStatusEvent.NET_STATUS, onFlushStatus);
}

If shared object is blocked u can catch the error report else if 0 it goes to SharedObjectFlushStatus.PENDING.

SOURCE

like image 91
Benny Avatar answered Sep 20 '22 10:09

Benny