2

UrlLoader.load()在我的 Flash 应用程序中使用。当发生未捕获的异常时,
我正在处理停止应用程序。当您正常连接互联网时工作。 但是,如果在您的浏览器加载应用程序后与 Internet 的连接丢失, 则会在调用时发生。 我无法通过使用捕获 SecurityError并且发生了 UNCAUGHT_ERROR 并且它停止了我的应用程序。 我不想在失败时停止应用程序,因为我只是用来记录一些不重要的信息。 而且我认为如果加载时间很长,也会发生超时错误。 而且我也不想因为超时错误而停止我的应用程序。 我该如何解决这些问题?UncaughtErrorEvent.UNCAUGHT_ERROR

UrlLoader.load()
SecurityErrorUrlLoader.load()

try catch

UrlLoader.load()UrlLoader.load()





还有更多其他类型的错误会发生并停止我的应用程序吗?

4

1 回答 1

2

当发生某种类型的安全违规时,会引发 SecurityError 异常。

安全错误示例:

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.

假设我们必须从任何外部 URL 加载 swf,然后:

    // 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;
 }

希望这对你有用。

于 2011-10-06T08:49:37.667 回答