Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 3.0 (http://www.flasher.ru/forum/forumdisplay.php?f=83)
-   -   Не могу словить ошибку (http://www.flasher.ru/forum/showthread.php?t=118432)

incvizitor 24.11.2008 00:05

Не могу словить ошибку
 
Вот есть такой код:

Код AS3:

public function GalleryItem(url:String,w,h=null)
{
        var loader=new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaded)
        var req=new URLRequest(url);
        try
        {
                loader.load(req);
        }
        catch(err:IOError)
        {
                trace(1);
        }
}

Если ссылка ненайдена output должен быть "1".
А получается вот этот:

Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.

Gaen 24.11.2008 01:39

Код AS3:

loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);


incvizitor 24.11.2008 03:10

Спасибо. А что за SecurityErrorEvent ???

Gaen 24.11.2008 03:59

Код:



An object dispatches a SecurityErrorEvent object to report the occurrence of a security error.
Security errors reported through this class are generally from asynchronous operations, such as loading data, in which security violations may not manifest immediately.
Your event listener can access the object's text property to determine what operation was attempted and any URLs that were involved.
If there are no event listeners, the debugger version of Flash Player or the AIR Debug Launcher (ADL) application automatically displays an error message that contains
the contents of the text property.
There is one type of security error event: SecurityErrorEvent.SECURITY_ERROR.

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/SecurityErrorEvent.html

Возникает, например, когда мы пытаемся стучаться в инет из файла, открытого локально и опубликованного с дефолтной установкой Access local files only

SamFR 25.11.2008 03:30

Это – пример асинхронной ошибки. Такие ошибки отлавливаются не блоком try...catch, а соответствующими обработчиками событий. IOErrorEvent – ошибка ввода-вывода (например, файл не найден).

BoUnd 25.11.2008 11:23

Цитата:

Сообщение от GAIKER (Сообщение 779280)
Код AS3:

loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);


У класса LoaderInfo нет события SecurityErrorEvent.SECURITY_ERROR, исключения SecurityError производятся непосредственно методом load класса Loader, о чем можно удостоверится в справке. Соответственно для перехвата следует воспользоваться кодом вида:
Код AS3:

try {
  loader.load(...);
} catch (error:SecurityError) {
  trace(error);
}


SamFR 25.11.2008 11:45

Да, насчёт SecurityError Вы правы. Да и по логике, плеер в момент запроса на загрузку уже знает, можно это делать, или нет. Поэтому это – не асинхронная ошибка.

А насчёт IOErrorEvent – всё в силе, только через события.


Часовой пояс GMT +4, время: 19:23.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.