1

我偶尔会弹出这个错误:

错误 #2044:未处理的错误:。文字=

我的代码在这里:

    private var _myLoader:URLLoader = new URLLoader();

    public function load():void {       
        var finalURL = http://xxxxx.com/service_staging.php/next;

        var myRequest:URLRequest = new URLRequest(finalURL);

        // add event listeners
        this._myLoader.addEventListener(Event.COMPLETE, this._completeHandler);
        this._myLoader.addEventListener(Event.OPEN, this._openHandler);
        this._myLoader.addEventListener(ProgressEvent.PROGRESS, this._progressHandler);
        this._myLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this._securityErrorHandler);
        this._myLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, this._httpStatusHandler);
        this._myLoader.addEventListener(IOErrorEvent.IO_ERROR, _ioErrorHandler);

        try {
            this._myLoader.load(myRequest);
        } catch (_error:SecurityError) {
            Logger.error('JSONRequest.as - catch: A SecurityError has occurred:', _error);

        } catch(_error:IOErrorEvent) {
            Logger.error("JSONRequest.as - catch: IOErrorEvent:", _error);      

        } catch(_error:Error) {
            Logger.error("JSONRequest.as - catch: Error catch: ", _error);
        }
    }   

    //----------------------------------------------------------    

    private function _completeHandler(event:Event):void {           
        Logger.info('JSONRequest.as - _completeHandler()');


        Logger.info('this._myLoader.data', this._myLoader.data);

        // decode the object
        this._JSONObject = JSON.decode(this._myLoader.data);

        // dispatch the complete event
        this.dispatchEvent(new Event(Event.COMPLETE));
    }   

    //----------------------------------------------------------    

    private function _ioErrorHandler(_error:IOErrorEvent):void {
        Logger.error('JSONRequest.as - _ioErrorHandler()');

        dispatchEvent(new ErrorEvent(ErrorEvent.ERROR));
    }

    //----------------------------------------------------------

    private function _securityErrorHandler(_event:SecurityErrorEvent):void {
        Logger.info("JSONRequest.as - _securityErrorHandler(): ", _event);

        dispatchEvent(new ErrorEvent(ErrorEvent.ERROR));
    }

    //----------------------------------------------------------

    private function _openHandler(event:Event):void {
       Logger.info("JSONRequest.as - openHandler: " + event);
    }

    //----------------------------------------------------------

    private function _progressHandler(event:ProgressEvent):void {
        Logger.info("JSONRequest.as - progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
    }

    //----------------------------------------------------------

    private function _httpStatusHandler(event:HTTPStatusEvent):void {
        Logger.info("JSONRequest.as - httpStatusHandler: " + event);
        Logger.info("status: " + event.status);
    }

    //----------------------------------------------------------

    public function get JSONObject():Object {
        return this._JSONObject;
    }

    //----------------------------------------------------------

如果从服务中获取 JSON 数据时出现问题,我已经处理了,但是即使我正在监听它,这个错误似乎仍然会弹出。

任何想法将不胜感激。

谢谢。

4

3 回答 3

2

您应该将这些侦听器添加到 _myLoader.contentLoaderInfo

this._myLoader.contentLoaderInfo.addEventListener(Foo.BAR, onFooBar);
于 2012-02-15T17:26:30.167 回答
1

要从 URLLoader 捕获 Unhandled IOError,您需要以下帮助UncaughtErrorEvents

loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onGlobalError);


private function onGlobalError(e:UncaughtErrorEvent):void {
    e.preventDefault();
    trace("ERROR: " + e.toString());
}

//Trigget it...
var urlLoader: URLLoader = new URLLoader();
urlLoader.load(new URLRequest("somewhere/nowhere"));
于 2014-03-20T10:37:51.360 回答
0

首先,您需要有关此错误的更多信息……堆栈、ErrorEvent 的目标等。

您是否尝试过监听 UncaughtErrorEvent.UNCAUGHT_ERROR ?这在以下示例中得到了很好的解释:http: //help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/LoaderInfo.html#uncaughtErrorEvents 并允许您捕获任何未捕获的错误,包括未处理的错误ErrorEvent 错误并选择如何处理。

我首先建议获取尽可能多的调试信息,放置断点var errorEvent:ErrorEvent = event.error as ErrorEvent;

希望在这个阶段你会有一个修复,或者至少是一个解决方法(只需在这个断点之后添加你的错误处理代码)

于 2014-03-20T10:50:02.220 回答