我在我的Flash应用中使用UrlLoader.load()
当发生未捕获的异常时,我正在处理UncaughtErrorEvent.UNCAUGHT_ERROR
以停止应用
当您正常连接互联网时,UrlLoader.load()
会正常工作
但是,如果在您的浏览器加载应用程序后丢失了与互联网的连接,
调用SecurityError
时会发生UrlLoader.load()
我无法通过使用try catch
捕获SecurityError并且UNCAUGHT_ERROR发生并且它会停止我的应用。
UrlLoader.load()
失败时我不想停止应用,因为我只是使用UrlLoader.load()
来记录一些不重要的信息。
而且我认为如果需要很长时间才能加载,也会出现超时错误
由于超时错误,我也不想停止我的应用程序
我该如何解决这些问题呢?
还有更多其他类型的错误可以发现并停止我的应用程序吗?
答案 0 :(得分: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;
}
希望这对你有用。