将应用程序状态保存在磁盘或某个地方,以便用户稍后访问它 [英] Save Application state on Disk or some where so user access it later

查看:15
本文介绍了将应用程序状态保存在磁盘或某个地方,以便用户稍后访问它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

flex builder 4.5 中,我正在开发一个类似 cacoo 的项目.我想在将应用程序关闭到某个地方之前保存 diagrams(display object,ui components,text),而不是在应用程序再次打开后我可以访问.

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 图表并将其保存以供稍后编辑并关闭应用程序.几天后他/她想要编辑以前保存的图表.现在我如何保存这个图表以备将来编辑.

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.

推荐答案

如果保存/打开对话框对您有用,您可以使用 FileReference API.在执行此操作之前,您必须将状态序列化/反序列化为 String/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()).

Similarly with restoring the state (use FileReference.browse(), then FileReference.load()).

如果您需要在没有任何对话框的情况下保存/恢复应用程序状态,那么您可能应该使用 AIR(或 SharedObject,正如 Raja 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 或 smth 之类的 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.

这篇关于将应用程序状态保存在磁盘或某个地方,以便用户稍后访问它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆