source: ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/common/components/SaveItemDialog.as @ 117

Last change on this file since 117 was 117, checked in by patdui, 14 years ago
  • completely reworked package structure
  • added styleing stuff in css files
File size: 1.4 KB
Line 
1package clarin.cmdi.componentregistry.common.components {
2        import clarin.cmdi.componentregistry.common.ItemDescription;
3
4        import flash.events.ErrorEvent;
5        import flash.events.Event;
6        import flash.events.IOErrorEvent;
7        import flash.events.SecurityErrorEvent;
8        import flash.net.FileReference;
9        import flash.net.URLRequest;
10        import flash.net.URLVariables;
11
12        import mx.controls.Alert;
13
14        public class SaveItemDialog {
15
16                private var ref:FileReference;
17
18                public function SaveItemDialog() {
19                }
20
21                public function saveAsXML(item:ItemDescription):void {
22                        save(item, "xml");
23                }
24
25                public function saveAsXSD(item:ItemDescription):void {
26                        save(item, "xsd");
27                }
28
29                private function save(item:ItemDescription, extension:String, urlVariable:String = null):void {
30                        ref = new FileReference()
31                        var req:URLRequest = new URLRequest();
32                        req.url = item.dataUrl + "/" + extension;
33                        try {
34                                ref.download(req, item.name + "." + extension);
35                        } catch (error:Error) {
36                                trace("Unable to download file.");
37                        }
38                        ref.addEventListener(Event.COMPLETE, saveComplete);
39                        ref.addEventListener(IOErrorEvent.IO_ERROR, saveError);
40                        ref.addEventListener(SecurityErrorEvent.SECURITY_ERROR, saveError);
41                }
42
43                private function saveComplete(event:Event):void {
44                        Alert.show("Saved.", "OK", Alert.OK);
45                }
46
47                private function saveError(event:ErrorEvent):void {
48                        Alert.show("Error: " + event.text, event.type, Alert.OK);
49                }
50
51
52        }
53}
Note: See TracBrowser for help on using the repository browser.