Flex:FileReference 和 Image 未处理 IOErrorEvent

发布于 2024-08-29 14:15:28 字数 1140 浏览 6 评论 0原文

以下代码显示了一个按钮,允许您选择一个文件(应该是图像)并将其显示到图像组件中。当我选择无效图像(例如不支持的图像类型、Word 文档)时,出现以下错误:

“错误#2044:未处理的 IOErrorEvent:.text=错误#2124:加载的文件是未知类型。”< /strong>

我知道我可以将 FileFilter 传递给 FileReference:browse 调用,但这超出了重点。我的问题是...我想自己处理 IOErrorEvent,我缺少什么事件侦听器?

private var file:FileReference = new FileReference();

private function onBrowse():void {
    file.browse(null);
    file.addEventListener(Event.SELECT, handleFileSelect);
    file.addEventListener(Event.COMPLETE, handleFileComplete);
    file.addEventListener(IOErrorEvent.IO_ERROR, handleFileIoError);
}

private function handleFileSelect(event:Event):void {
    file.load();
}

private function handleFileComplete(event:Event):void {
    myImage.source = file.data;
}

private function handleFileIoError(event:Event):void {
    Alert.show("handleFileIoError");
}

private function handleImageIoError(evt:IOErrorEvent):void {
    Alert.show("handleImageIoError");
}

<mx:Button click="onBrowse()" label="Browse"/>
<mx:Image id="myImage" width="100" height="100" ioError="handleImageIoError(event)"/>

The following code shows a button that allows you to select a file (should be an image) and display it into an image component. When I select an invalid image (e.g. unsupported image type, a word document), I get the following error:

"Error #2044: Unhandled IOErrorEvent:. text=Error #2124: Loaded file is an unknown type."

I know I can pass a FileFilter to the FileReference:browse call, but that's beyond the point. My question is... I want to handle the IOErrorEvent myself, what event listener am I missing?

private var file:FileReference = new FileReference();

private function onBrowse():void {
    file.browse(null);
    file.addEventListener(Event.SELECT, handleFileSelect);
    file.addEventListener(Event.COMPLETE, handleFileComplete);
    file.addEventListener(IOErrorEvent.IO_ERROR, handleFileIoError);
}

private function handleFileSelect(event:Event):void {
    file.load();
}

private function handleFileComplete(event:Event):void {
    myImage.source = file.data;
}

private function handleFileIoError(event:Event):void {
    Alert.show("handleFileIoError");
}

private function handleImageIoError(evt:IOErrorEvent):void {
    Alert.show("handleImageIoError");
}

<mx:Button click="onBrowse()" label="Browse"/>
<mx:Image id="myImage" width="100" height="100" ioError="handleImageIoError(event)"/>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥枳 2024-09-05 14:15:28

不幸的是,这是 Flex SDK 的一个错误。看一下 SWFLoader 的 loadContent 方法。它没有针对多种情况(包括您的情况)的错误处理程序。该错误已在 SDK 3.4 中修复,因此进行更新可能是个好主意。

Unfortunately it is a bug from Flex SDK. Take a look on SWFLoader, method loadContent. It does not have a handler for errors for several cases (your included). The bug is fixed in SDK 3.4 , so it maybe a good idea to do an update.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文