Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 4 of 4

Thread: SharedObject and error handling

  1. #1

    SharedObject and error handling


    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:
    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);
          case SharedObjectFlushStatus.FLUSHED:
            trace("Value flushed to disk.");
    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.");
        case "SharedObject.Flush.Failed":
          trace("User denied permission -- value not saved.\n");
       _so.removeEventListener(NetStatusEvent.NET_STATUS, onFlushStatus);
    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.

  2. #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.

  3. #3
    I'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?

  4. #4
    Actually 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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012