FileReference: loading a file with Windows lock

I use Flex in Flash Player 10 on Windows, using FileReference to load a file into memory, as shown below.

My problem is that when the file is locked by Windows, my FileReference does not give me any feedback that the file is unavailable - it just never sends any events after my load() call.

Does anyone know how to report that Flash Player cannot open the file?

 var fileReference:FileReference = new FileReference(); private function onClick():void { fileReference = new FileReference(); fileReference.addEventListener(Event.SELECT, onSelect); fileReference.addEventListener(Event.COMPLETE, onComplete); fileReference.addEventListener(Event.CANCEL, onOther); fileReference.addEventListener(IOErrorEvent.IO_ERROR, onOther); fileReference.addEventListener(ProgressEvent.PROGRESS, onOther); fileReference.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onOther); // I've tried adding all of the other declared events // for FileReference here as well fileReference.browse(); } private function onSelect(event:Event):void { trace(fileReference.name); try { fileReference.load(); } catch (e:Error) { trace(e); } } private function onComplete(event:Event):void { trace(fileReference.data.length); } private function onOther(event:Event):void { trace("other:" + event.toString()); } 
+7
flex windows flash actionscript-3 filereference
source share
1 answer

A possible (dirty) workaround might be to wait for -let say-10 seconds, and suppose the file is not available if the event was not triggered.

Using setTimeout (and clearing it with clearTimeout in COMPLETE and *_ERROR ) can do the trick.

I will be glad if someone comes up with a more pleasant solution.


EDIT: Of course, you can listen to the HTTP_STATUS event (waiting for a 202 response - if I understood this documentation correctly), and not expecting a COMPLETE or *_ERROR .

+2
source share

All Articles