Created
May 30, 2011 08:00
-
-
Save peterblazejewicz/998586 to your computer and use it in GitHub Desktop.
save xml with flash.net.FileReference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" | |
xmlns:s="library://ns.adobe.com/flex/spark" | |
xmlns:mx="library://ns.adobe.com/flex/mx" | |
width="320" height="480" | |
applicationComplete="mdm.Application.init(this);" | |
creationComplete="Controller.instance.model.existingDataObj.existingDataXML = xml;"> | |
<fx:Declarations> | |
<fx:XML format="e4x" id="xml" xmlns=""> | |
<root label="Menu"> | |
<menuitem label="MenuItem A"> | |
<menuitem label="SubMenuItem 1-A"/> | |
<menuitem label="SubMenuItem 2-A" /> | |
</menuitem> | |
<menuitem label="MenuItem B"/> | |
<menuitem label="MenuItem C" type="check"/> | |
<menuitem type="separator"/> | |
<menuitem label="MenuItem D"> | |
<menuitem label="SubMenuItem 1-D" type="radio" groupName="one"/> | |
<menuitem label="SubMenuItem 2-D" type="radio" groupName="one"/> | |
<menuitem label="SubMenuItem 3-D" type="radio" groupName="one"/> | |
</menuitem> | |
</root> | |
</fx:XML> | |
</fx:Declarations> | |
<fx:Script> | |
<![CDATA[ | |
import mdm.Application; | |
// | |
// | |
private var Controller:Object = { | |
instance: { | |
model: { | |
existingDataObj: {} | |
} | |
} | |
}; | |
// | |
[Bindable] | |
private var txt:String = ""; | |
private function debug(msg:*):void | |
{ | |
trace(msg); | |
txt += msg.toString()+"\n"; | |
}; | |
// | |
private var fr:flash.net.FileReference = null; | |
protected function saveXMLHandler(event:MouseEvent):void | |
{ | |
fr = new FileReference(); | |
var objXML:XML = Controller.instance.model.existingDataObj.existingDataXML; | |
fr.addEventListener(Event.CANCEL, saveCancelHandler); | |
fr.addEventListener(Event.COMPLETE, saveCompleteHandler); | |
try | |
{ | |
fr.save(objXML, "data.xml"); | |
} catch(error:Error) | |
{ | |
debug("ERROR!!: "+error.name+" "+error.errorID+" "+error.message); | |
} | |
}; | |
// | |
protected function saveCancelHandler(event:Event):void | |
{ | |
debug(event.type); | |
}; | |
protected function saveCompleteHandler(event:Event):void | |
{ | |
debug(event.type); | |
debug("creationDate: "+fr.creationDate); | |
debug("size: "+fr.size); | |
}; | |
// | |
private function cleanup():void | |
{ | |
fr.removeEventListener(Event.CANCEL, saveCancelHandler); | |
fr.removeEventListener(Event.COMPLETE, saveCompleteHandler); | |
fr = null; | |
} | |
]]> | |
</fx:Script> | |
<s:Button x="10" y="10" width="300" label="Save XML" click="saveXMLHandler(event)"/> | |
<s:Label x="10" y="39" width="300" height="431" text="{txt}"/> | |
</s:Application> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment