2

I use UrlLoader.load() in my flash app.
And I'm handling UncaughtErrorEvent.UNCAUGHT_ERROR to stop the app when an uncaught exception occured.

UrlLoader.load() works when you are connecting the internet normally.
But if the connection to the internet was lost after your browser loaded the app, SecurityError happens when UrlLoader.load() is called.

I can not catch the SecurityError by using try catch and UNCAUGHT_ERROR happens and it stops my app.

I don't want to stop the app when UrlLoader.load() failed because I'm just using UrlLoader.load() to log some unimportant information.

And I think timeout error also can be ocurred if it takes a long time to load.
And I also don't want to stop my app due to the time out error.

How can I solve those problems?
And are there more other type of errors which can be ocurred and stop my app?

js_
  • 4,671
  • 6
  • 44
  • 61
  • what do you mean by uncaught exception because it is always find any type of exception or error then it will stop your app. if you want to prevent from security error then you should try IOErrorEvent.IO_ERROR. can you please be clear about uncaught exception? – Swati Singh Oct 06 '11 at 05:22
  • @SwatiSingh thanks for your comment. Uncaught exceptions just stop the process not the application. The app just stops responding to user input and the users can't understand whether the app stopped or not. So I stop the app by clearing all objects and show an error message on the screen when UncaughtErrorEvent.UNCAUGHT_ERROR occurred. If I don't stop the app by handling UncaughtErrorEvent.UNCAUGHT_ERROR, SecurityError of UrlLoader.load() is just ignored and the app continues normally because UrlLoader.load() is async function and doesn't affect the main process of the app. – js_ Oct 06 '11 at 05:47

1 Answers1

2

The SecurityError exception is thrown when some type of security violation takes place.

Examples of security errors:

An unauthorized property access or method call is made across a security sandbox boundary.
An attempt was made to access a URL not permitted by the security sandbox.
A socket connection was attempted to an unauthorized port number, e.g. a port above 65535.
An attempt was made to access the user’s camera or microphone, and the request to access the device was denied by the user.

Lets say we have to load an swf from any external URL then:

    // URL of the external movie content
    var myRequest:URLRequest=new URLRequest("glow2.swf");

    // Create a new Loader to load the swf files
    var myLoader:Loader=new Loader();

    // 1st level IO_ERROR input and output error checking
    // Listen error events for the loading process
    myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);

    function ioError(event:ErrorEvent):void 
    {
      // Display error message to user in case of loading error.
         output_txt.text = "Sorry that there is an IO error during the loading of  an  
                            external movie. The error is:" + "\n" + event;
    }

    function checkComplete(evt:MouseEvent) 
    {
      // 2nd level SecurityError error checking
      // Use the try-catch block
      try
      {
         // Load the external movie into the Loader
         myLoader.load(myRequest);
      }
      catch (error:SecurityError) 
      {
         // catch the error here if any
         // Display error message to user in case of loading error.
            output_txt.text = "Sorry that there is a Security error during the 
                               loading of an external movie. The error is:" + "\n" +
                               error;
      }
    }

 movie1_btn.addEventListener(MouseEvent.CLICK, checkComplete);

 // Listen when the loading of movie (glow.swf) is completed
 myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadMovie1);

 function loadMovie1(myEvent:Event):void 
 {
     // Display the Loader on the MainTimeline when the loading is completed
     addChild(myLoader);
     // Set display location of the Loader
     myLoader.x = 200;
     myLoader.y = 80;
 }

Hope this will work for you.

Swati Singh
  • 1,863
  • 3
  • 19
  • 40