ActionScript 加载器事件出现问题
我正在使用加载程序从 WMS(网络地图服务)请求图像。一切都很好,有一个有效的请求。
当向 WMS 发出错误请求时,通常会返回标准异常文档 (XML)。但是,当发出错误请求时,加载程序不会触发任何事件(特别是 Complete 或 IOError 事件)。
有人对我如何捕获任何不是可能返回的图像的东西有任何建议吗?
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');
}
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');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以考虑的一种可能性是将您的 Loader 转换为 URLLoader,以便让您更灵活地查看实际请求/接收的数据。
display.Loader 类有一些奇怪的怪癖,如果它尝试加载没有正确入口类(通常是从 display.Sprite 派生的类)的对象,则根本不允许触发某些事件。
我认为 URLLoader 会很有用,因为您可以将 URLLoaderDataFormat 设置为 BINARY。这将捕获返回的任何内容并将其存储在 ByteArray 对象中,如果它是有效图像,您可以通过 Loader.loadBytes() 将其加载到 display.Loader 中,或者简单地转换 URLLoaderData.toString() 以检索 XML信息。
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.