开发者

If URLRequest return error, or not exist

开发者 https://www.devze.com 2022-12-16 06:02 出处:网络
I want it to do another action if the ID I key in does not exist or have an error, how do I trace the error event?

I want it to do another action if the ID I key in does not exist or have an error, how do I trace the error event?

loadID=searchArea.text;
myLoader2.load(new URLRequest("GetData.aspx?id="+lo开发者_高级运维adID));

if (errorEvent) {
trace("Please key in the correct ID");
} else {
myLoader2.addEventListener(Event.COMPLETE,processXML2);
}


You would need to add an event listener for the error event as well. something like:

loadID=searchArea.text;

myLoader2.addEventListener(Event.COMPLETE,processXML2);
myLoader2.addEventListener(IOErrorEvent.IO_ERROR,onIOError);

myLoader2.load(new URLRequest("GetData.aspx?id="+loadID));

then create a method to hanel the IO error event.

public function onIOError(e:IOErrorEvent):void
{
    // do error handling in here
    trace("Please key in the correct ID");
}


See this page.

excerpt:

public function URLRequestExample() {
    var loader:URLLoader = new URLLoader();
    configureListeners(loader);

    var request:URLRequest = new URLRequest("XMLFile.xml");
    try {
        loader.load(request);
    } catch (error:Error) {
        trace("Unable to load requested document.");
    }
}

private function configureListeners(dispatcher:IEventDispatcher):void {
    dispatcher.addEventListener(Event.COMPLETE, completeHandler);
    dispatcher.addEventListener(Event.OPEN, openHandler);
    dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
    dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
    dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
    dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}

private function completeHandler(event:Event):void {
    var loader:URLLoader = URLLoader(event.target);
    trace("completeHandler: " + loader.data);
}

private function openHandler(event:Event):void {
    trace("openHandler: " + event);
}

private function progressHandler(event:ProgressEvent):void {
    trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
}

private function securityErrorHandler(event:SecurityErrorEvent):void {
    trace("securityErrorHandler: " + event);
}

private function httpStatusHandler(event:HTTPStatusEvent):void {
    trace("httpStatusHandler: " + event);
}

private function ioErrorHandler(event:IOErrorEvent):void {
    trace("ioErrorHandler: " + event);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消