0

我正在创建一个思维导图 Flash 应用程序,该应用程序必须保存导入到单个文件夹中的所有图像,以及用于数据存储的 xml。虽然我当前的应用程序在未嵌入 HTML 时可以正常工作,但由于安全违规,它会立即中断。

通过单击保存按钮,代码循环遍历图像数组并为每个图像创建一个 FileReference 并调用 FileReference.save 来保存图像。

如本文档所述,每次保存都需要由 UI 交互触发:http: //kb2.adobe.com/cps/405/kb405546.html

但它也指出可以通过从同一个函数调用它们来进行一系列保存。

但是,使用我的图像数组循环,只有第一个图像被保存,并且没有为后续图像调用弹出窗口。我的猜测是一次只允许一个本地弹出窗口,但我将如何去做呢?有没有人尝试过链接文件引用?

4

1 回答 1

1

将文件引用推送到向量中,添加事件侦听器以侦听每个文件引用的 Event.COMPLETE 回调。然后,在回调内部,将文件引用从数组中弹出并调用下一个 cue。

var myFiles:Vector.<FileReference> = new Vector.<FileReference>();

//Populate the vector (this example assumes you can figure this out

//While populating the vector, add the event listener to the file reference for the COMPLETE event.
myRef.addEventListener(Event.COMPLETE, onFileSaved);
myFiles.push(myRef);

private function onFileSaved(e:Event):void
{
    var i:int = 0;
    for(i; i < myFiles.length; ++i){
        if(myFiles[i] == FileReference(e.currentTarget)){
            FileReference(e.currentTarget).removeEventListener(Event.COMPLETE, onFileSaved);
            myFiles.splice(i, 1);
        }
    }

    if(myFiles.length > 0){
        FileReference(myFiles[0]).save();
    }
}

因此,此代码未经测试,还必须适应您的特定场景,但无论如何您都会明白这一点。

于 2011-04-04T11:37:27.893 回答