How to Load and Save GraphML Files Without a Sever

Questions & Answers

Summary

For loading and saving GraphML yFiles FLEX provides a DownloadHandler and an UploadHandler. These handlers require a server component. This article shows how to load/save files and export images without the requirement for a server.

Description

Since version 1.7 yFiles FLEX supports loading and saving files without a server. The new classes LoadHandler and SaveHandler support loading and saving GraphML files directly to the client's file system. The ImageSaveHandler exports bitmap images to the client's file system.

With Flash Player 9 it was not possible to load or save files on the file system. yFiles FLEX works around this limitation by simulating an upload / download: the UploadHandler uses the browser's upload functionality to send a file to the server and expects the file data as the server's response. The download handler sends the file data to the server which sends it back as response. Flash Player's FileReference uses the browser's download mechanism to save the received file to the local file system.

With Flash Player 10 / Flex 3.2 Adobe introduced a new load and save functionality. Now it's possible to load and save files directly from/to the local file system without the requirement for a server. As yWorks decided to keep compatibility with Flash Player 9 / Flex 3.0 we didn't include this functionality into the library.

A modified version of the DownloadHandler and the UploadHandler can be found as attachment at the bottom of this article. The SaveHandler and LoadHandler can be used as demonstrated below:

private function load():void { var handler:LoadHandler = new LoadHandler(); handler.addEventListener(XMLResultEvent.COMPLETE, function(event:XMLResultEvent):void { graphCanvas.fitGraphBounds(); }); handler.load(graphCanvas.graph, "test.graphml"); } private function save():void { var handler:SaveHandler = new SaveHandler(); handler.save(graphCanvas.graph, "test.graphml"); }

Image export

The same applies for image export. A replacement for the yFiles FLEX ImageExportHandler is also provided as attached resource. The FileImageExportHandler saves images of the graph canvas directly as file. It can be used exactly the same way as the original ImageExportHandler

Resources

Categories this article belongs to:
yFiles FLEX > Input and Output
Applies to:
yFiles FLEX: 1.4, 1.5, 1.6, 1.7, 1.8
Keywords:
load - save - FileReference - load GraphML - save GraphML - UploadHandler - DownloadHandler - ImageExportHandler - image export