Flex 上传文件组件 - 文件引用问题

发布于 2024-09-17 08:03:35 字数 1178 浏览 0 评论 0原文

以下代码在我命名为 FileUpload.mxml 的组件中使用,该组件在 Flex 应用程序的两个三个不同部分中使用。

private var uploadURL:URLRequest = new URLRequest;
private var file:FileReference = new FileReference;
private var media:MediaFacade;

public function browse():void
{
        var uUrl:String=""; // force
        uploadURL=new URLRequest();

        file=new FileReference();
        configureListeners();

        file.browse(getTypes());
}

private function configureListeners():void
{
    file.addEventListener(Event.CANCEL, cancelHandler);
            ...
    if (!Application.application.hasEventListener("uploadFileEvent")) {
        Application.application.addEventListener("uploadFileEvent", uploadFile);
    }
}

当它在第一个实例中使用时,它工作正常,但是当它在不同的部分中使用时,它会从下面的代码中得到以下错误:

错误#2037:以错误的顺序调用函数,或者之前的调用不成功。

    private function doUploadFile():void
    {
        try
        {
            file.upload(uploadURL);
        }
        catch (e:Error) {
            trace(e.message);
        }
    }

每次都遵循相同的顺序,即 file=new FileReference;配置文件监听器(文件);文件.浏览(); file.upload(uploadURL) 但仅适用于正在创建的组件的第一个实例。

任何想法将不胜感激。

提前致谢。

安格斯。

The following code is used in a component I name FileUpload.mxml which is used in two three different sections of the flex application.

private var uploadURL:URLRequest = new URLRequest;
private var file:FileReference = new FileReference;
private var media:MediaFacade;

public function browse():void
{
        var uUrl:String=""; // force
        uploadURL=new URLRequest();

        file=new FileReference();
        configureListeners();

        file.browse(getTypes());
}

private function configureListeners():void
{
    file.addEventListener(Event.CANCEL, cancelHandler);
            ...
    if (!Application.application.hasEventListener("uploadFileEvent")) {
        Application.application.addEventListener("uploadFileEvent", uploadFile);
    }
}

When it is used in the first instanced, it works fine, but when it is used in different sections it gets the following error from the code below:

Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.

    private function doUploadFile():void
    {
        try
        {
            file.upload(uploadURL);
        }
        catch (e:Error) {
            trace(e.message);
        }
    }

It follows the same sequence every time, i.e., file=new FileReference; configureFileListeners(file); file.browse(); file.upload(uploadURL) but only works on the first instance of the component being created.

Any ideas would be appreciated.

Thanks in advance.

Angus.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

遥远的绿洲 2024-09-24 08:03:40

browse 方法只能从“用户交互”事件(例如 CLICK 事件)直接调用。如果将其包装在函数或类中,则会发生该错误。

browse method only can be call directly from "User-Interaction" event such as CLICK event. If you wrap it in a function or class than that error will occur.

吾性傲以野 2024-09-24 08:03:40

我是 Flex 的菜鸟,但从我读到的内容来看:

尝试在 .browse() 之前调用 .cancel() 以确保没有事件发生冲突。

I'm a noob at Flex, but from what I've read:

Try calling .cancel() before .browse() to ensure no event is conflicting.

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