views:

267

answers:

1

Hello,

I am working with a loader to request an image from a WMS(Web Mapping Service). Everything thing is fine and dandy with a valid request.

When a bad request is made to a WMS, a Standard Exception Document(XML) is usually returned. However, the loader doesn't fire any event (specifically the Complete or IOError events) when a bad request is made.

Does anyone have any suggestions on how I can trap anything that is not an image that might be returned?

override protected function loadMapImage(loader:Loader):void
{
// update parameter values
_params = new URLVariables();
_params.request = "GetMap";
_params.format = "image/png";
_params.version = "1.1.1";
_params.layers = this.layers;
_params.styles = "";
_params.transparent = "TRUE";
_params.bbox = map.extent.xmin + "," + map.extent.ymin + "," + map.extent.xmax + "," + map.extent.ymax;
_params.srs = "EPSG:" + map.spatialReference.wkid;
_params.width = map.width;
_params.height = map.height;

_urlRequest = new URLRequest(this.url);
_urlRequest.data = _params;

configureListeners(loader.contentLoaderInfo);

loader.load(_urlRequest);
}

private function configureListeners(dispatcher:IEventDispatcher):void 
{
//dispatcher.addEventListener(Event.INIT, initHandler);
//dispatcher.addEventListener(Event.UNLOAD, unloadHandler);
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);
//dispatcher.addEventListener(Event.ACTIVATE, activateHandler);
//dispatcher.addEventListener(Event.DEACTIVATE, deactivateHandler);
}

private function ioErrorHandler(event:IOErrorEvent):void
{
trace('ioErrorHandler event');
}

private function completeHandler(event:Event):void 
{
trace('completeHandler event');
}
+1  A: 

One possibility you could look into is converting your Loader to a URLLoader, as to give you more flexibility over seeing what data is actually being requested/received.

The display.Loader class has some strange quirks that simply won't allow certain events to fire if it attempts to load an object that does not have a proper entry class (typically a class derived from display.Sprite).

I think the URLLoader will be beneficial, as you can set the URLLoaderDataFormat to BINARY. This will catch whatever is returned and store it in a ByteArray object, which you can either load into a display.Loader via Loader.loadBytes() if it is a valid image, or simply convert the URLLoaderData.toString() to retrieve your XML information.

atomish
This worked perfectly, thanks for the advice.