Flex: FileReference and Image unhandled IOErrorEvent
Posted
by deux11
on Stack Overflow
See other posts from Stack Overflow
or by deux11
Published on 2010-04-21T23:10:45Z
Indexed on
2010/04/21
23:13 UTC
Read the original article
Hit count: 407
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. 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);
}
private function handleFileSelect(event:Event):void {
file.load();
}
private function handleFileComplete(event:Event):void {
myImage.source = file.data;
}
private function handleImageIoError(evt:IOErrorEvent):void {
Alert.show("IOErrorEvent");
}
<mx:Button click="onBrowse()" label="Browse"/>
<mx:Image id="myImage" width="100" height="100" ioError="handleImageIoError(event)"/>
© Stack Overflow or respective owner