FileReference:加载 Windows 锁定文件

发布于 2024-08-24 03:52:00 字数 1378 浏览 7 评论 0原文

我在 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 技术交流群。

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

发布评论

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

评论(1

鹿港巷口少年归 2024-08-31 03:52:00

一个可能的(肮脏的)解决方法可能是等待 - 比方说 - 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 with clearTimeout in your COMPLETE 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 for COMPLETE or *_ERROR.

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