Results 1 to 4 of 4
Thread: SharedObject and error handling
-
August 3rd, 2008, 05:48 AM #17Registered User
postsSharedObject and error handling
Hi.
I'm trying to make a SharedObject for storing small data on the users harddrive. Max usage should probably be 2-3 kB.
I've been working with the example found here: http://livedocs.adobe.com/flash/9.0/...xamplesSummary and it seems to work. Only thing that doesn't really work is the error handling. I tried setting that my domain wasn't allowed to store anything, and it popped up a dialog asking for permission, which is the intended behavior.
my code looks like this:
If I click "Allow" when the dialog pops up, it works perfectly. But when I press "deny", I get am error message "Error #2044: Unhandled NetStatusEvent:. level=error, code=SharedObject.Flush.Failed", which I'm not sure how to handle. Tried adding a eventlistener, and a catch-block, but none of them worked.Code:private function write():void { var flushStatus:String; try { flushStatus = _so.flush(); } catch(error:Error) { trace("Unable to write contents to disk!"); } if(flushStatus != null) { switch(flushStatus) { case SharedObjectFlushStatus.PENDING: trace("Requesting permission to save object..."); _so.addEventListener(NetStatusEvent.NET_STATUS, onFlushStatus); break; case SharedObjectFlushStatus.FLUSHED: trace("Value flushed to disk."); break; } } } private function onFlushStatus(event:NetStatusEvent):void { trace("User closed permission dialog..."); switch(event.info.code) { case "SharedObject.Flush.Success": trace("User granted permission -- value saved."); break; case "SharedObject.Flush.Failed": trace("User denied permission -- value not saved.\n"); break; } _so.removeEventListener(NetStatusEvent.NET_STATUS, onFlushStatus); }
-
August 3rd, 2008, 11:45 AM #2
It looks like the event is asynchronous (so try-catch wouldn't help), and it looks like that event should come from the SharedObject _so.
Try adding the NetStatusEvent listener right after your getLocal() statement. Your current addEventListener() function call is only reached if flushStatus == SharedObjectFlushStatus.PENDING, which just might not be the case (for some strange reason) when the problematic NetStatusEvent is dispatched.
-
August 4th, 2008, 03:41 AM #37Registered User
postsI've removed every single attempt at writing to the SharedObject. Now, when I load it, it attempts to create the object, and starts to ask for permission. It looks like this happens before my event listeners is added, which might explain why it doesn't run the code, and claims that I've failed to handle the event.
But then, how can I work around this? Adding the event listeners before the call to getLocal obviously fails, since _so is null. Instanciating _so using new SharedObject gives me a error, since it's not supposed to be used that way, and every other idea I have also fails. Any thoughts?
-
August 4th, 2008, 05:47 AM #47Registered User
postsActually reading the error messages I get is usually a good idea. Discovered that my problems happen much earlier, in the loader-file, which I hadn't even looked at. That creates a SharedObject without any kind of error handling, so that's where the errors appear. Solved my problem now.

Reply With Quote

Bookmarks