FileReference:加载 Windows 锁定文件
我在 Windows 上的 Flash Player 10 中使用 Flex,使用 < code>FileReference 将文件加载到内存中,如下所示。
我的问题是,当 Windows 锁定文件时,我的 FileReference 不会向我提供该文件无法访问的任何反馈 - 在我调用 load() 之后,它根本不会调度任何事件/代码>。
有谁知道如何判断 Flash Player 无法打开该文件吗?
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());
}
I'm using Flex in Flash Player 10 on Windows, using FileReference
to load a file into memory, as below.
My issue is that when a file is locked by Windows, my FileReference
is not giving me any feedback that the file is inaccessible--it simply never dispatches any events after my calling load()
.
Does anyone have insight into how to tell that Flash Player is unable to 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());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个可能的(肮脏的)解决方法可能是等待 - 比方说 - 10 秒,并假设如果没有事件触发则文件不可用。
使用
setTimeout
(并在COMPLETE
和*_ERROR
事件处理程序中使用clearTimeout
清除它)可能会成功。不过,如果有人能提出更好的解决方案,我会很高兴。
编辑:当然,您可能想监听
HTTP_STATUS
事件(等待 202 答案 - 如果我理解 此文档正确),而不是等待COMPLETE
或*_ERROR
。A possible (dirty) workaround might be to wait for -let say- 10 seconds, and suppose that the file isn't available if no event has triggered then.
Using a
setTimeout
(and clearing it withclearTimeout
in yourCOMPLETE
and*_ERROR
events handlers) might do the trick.I'll be glad if someone could come up with a nicer solution, though.
EDIT: Of course you might want to listen to
HTTP_STATUS
event (waiting for a 202 answer - if I understood this documentation correctly) rather than waiting forCOMPLETE
or*_ERROR
.