保存应用程序状态在磁盘或一些地方让用户访问它以后磁盘、应用程序、状态、地方

2023-09-08 14:09:46 作者:此女子╭ァ冭过單純

在的Flex Builder 4.5 我的工作就像一个项目 cacoo 。  我想保存图(显示对象,UI组件,文本)关闭应用程序到什么地方比我能申请后访问的再次打开

In flex builder 4.5 i'm working on a project like cacoo. I want to save diagrams(display object,ui components,text) before close the application into somewhere than I would be able to access after the application open again.

更清楚: - 如果用户编辑在这个项目上的一些UML图,并将其保存为编辑后并关闭application.after有些日子,他/她想要编辑的 previously保存图。 现在我是如何保存此图以供将来编辑。

more clear:-If user edit some uml diagram on this project and save it for edit later and close application.after some days he/she want to edit previously saved diagram. now how i'm save this diagram for future edit.

推荐答案

如果保存/打开对话框,会为你工作,你可以YSE 的FileReference API。在此之前,你必须从字符串 / 的ByteArray / XML 对象。

If save/open dialog will work for you, you can yse FileReference API. Before doing this, you have to implement serialization/deserialization of your state into/from String/ByteArray/XML object.

private var fileReference:FileReference;

// due to security restrictions, this method must be called from an
// event handler that responds to a user event (mouse click or key
// press), otherwise it will fail.

private function saveState(serializedState:*, fileName:String):void {
    fileReference = new FileReference();

    fileReference.addEventListener(Event.COMPLETE, onSaved);
    fileReference.addEventListener(IOErrorEvent.IO_ERROR, onSavingError);

    try {
        fileReference.save(serializedState, fileName); // will open save dialog
    } catch (e:Error) {
        trace("error saving data: " + e.toString());
        freeListeners();
    }
}

private function onSaved(e:Event):void {
    trace("saved!");
    freeListeners();
}

private function onSavingError(e:ErrorEvent):void {
    trace("error saving data: " + e.toString());
    freeListeners();
}

private function freeListeners():void {
    fileReference.removeEventListener(Event.COMPLETE, onSaved);
    fileReference.removeEventListener(IOErrorEvent.IO_ERROR, onSavingError);
}

同样与恢复状态(使用 调用FileReference.browse() ,那么 FileReference.load() )。

如果您需要保存/恢复应用程序的状态,没有任何对话,那么你或许应该使用空气(或共享对象,因为拉贾Jaganathan建议)。但它似乎是不是这种情况,根据需要,用户能够在另一个系统重新打开该图。要做到这一点,你应该允许用户对他的工作保存到适当的地方,所以后来他就可以将其移动到另一台机器/系统并重新打开它与你的应用程序。

If you need to save/restore app state without any dialogs, then you should probably use AIR (or SharedObject, as Raja Jaganathan suggested). But it seems to be not the case, as you want the user to be able to re-open the diagram in another system. To achieve this, you should allow the user to save his work to the appropriate place, so later he can move it to another machine/system and re-open it with your application.

另一种选择是存储一切在服务器上,并提供与保存的文件的列表的用户(象Cacoo一样)。如果你走这条路,你必须执行相应的服务器端API。这可能是REST API或像水木清华RTMP服务器。在REST API的情况下,使用 FileReference.upload()将数据上传到服务器,而 URLLoader.load()的获得了回去。

Another alternative is to store everything on the server and provide the user with a list of saved files (like Cacoo does). If you go this way, you'll have to implement the corresponding server-side API. It may be REST API or smth like RTMP server. In the case of REST API, use FileReference.upload() to upload the data to your server, and URLLoader.load() to obtain it back.