View Full Version : save as .txt.
Guest
11-17-2009, 12:40 PM
Hi..
Is there any way in flex 3 to save the input text as .txt in a local system. Without using server side scripting.
Barna Biro
11-17-2009, 04:37 PM
If you are targeting Flash Player 10 then you can user the FileReference class to save files locally. If you are targeting earlier Flash Player versions then you'll need to do some server-side scripting to achieve the saving. Good luck. ;)
Guest
11-18-2009, 09:31 AM
Thanks for the reply.
yes am using flash player 10 and sdk 4 in flex builder 3.But when i try to compile it getting some error like. Could not resolve <Application> to a component implementation. Can you provide a link for the tutorials or sample file. I tried this. http://blog.flexexamples.com/2008/08/25/saving-files-locally-using-the-filereference-classs-save-method-in-flash-player-10/
Barna Biro
11-18-2009, 10:22 PM
Try changing the <Application> tags to <mx:Application> and close it with </mx:Application>. Also make sure that the "mx" namespace is defined: xmlns:mx = "http://www.adobe.com/2006/mxml". Unfortunately, I don't know of any tutorials... "my best friend" is called "LiveDocs" ( http://livedocs.adobe.com/flex/3/html/help.html?content=Part1_Using_FB_1.html and http://livedocs.adobe.com/flex/3/langref/index.html ).
Best wishes,
Barni
Guest
11-19-2009, 09:30 AM
Thanks for your reply.
Finally i get some other tutorial for save as text.
here is the mxml code.<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
/**
* @private
* The FileReference that does the saving and the loading
*/
private var fileReference:FileReference = new FileReference();
private function onSaveText():void
{
fileReference.save(myText.text,"myText.txt");
}
private function onLoadText():void
{
var f:FileFilter = new FileFilter("Text","*.txt");
fileReference.browse([f]);
fileReference.addEventListener(Event.SELECT,onFile Select);
fileReference.addEventListener(Event.COMPLETE,onFi leComplete);
}
private function onFileSelect(event:Event):void
{
fileReference.load();
}
private function onFileComplete(event:Event):void
{
myText.text = fileReference.data.readUTFBytes(fileReference.data .length);
}
]]>
</mx:Script>
<mx:Panel id="myPanel" width="400" height="450" verticalScrollPolicy="off"
horizontalScrollPolicy="off" title="Text Pad">
<mx:TextArea width="380" height="420" id="myText"
text="Hello You Can Save This to test this APP"/>
<mx:ControlBar>
<mx:Button label="Save Text" click="onSaveText()"/>
<mx:Button label="Load Text" click="onLoadText()"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.