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 handleFileIoErro开发者_如何学编程r(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)"/>
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.
精彩评论