How to Load and Save GraphML Files Without a Sever
Questions & AnswersSummary
Description
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