Language: ChineseGermanSpanishFrenchDutchItalianRussian
123 Flash Chat Forums

Go Back   TOPCMM Community > SWFKit > SWFKit Support

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-22-2006, 02:20 PM
Junior Member
 
Join Date: May 2006
Posts: 4
Default Opening text files

I have used a basic script to save the text from an input box.


var myTxt=FlashPlayer.getVariable("someTxt");
var filter = "Text Files(*.txt)|*.txt|";
var filename = Dialogs.fileSave(filter, ".txt");
if (filename)
{
file_stream = new FileStream(filename,"w");
trace(file_stream);
file_stream.write(myTxt);
trace(myTxt);
file_stream.close();
}//end of if(filename)
return true;

I want to now load the text (or other text) back into the box. I've tried the following script but all I can retrieve is the file name. What is it that I'm missing?

var txtFile = "Text File (*.txt)|*.txt|";
var filetoLoad = Dialogs.fileOpen(txtFile, "", "", true);
if((filetoLoad!=false) && (File.exists(filetoLoad))){
FlashPlayer.setVariable("_root.location",filetoLoa d);
var nameofFile = new File(filetoload);
filetoload = nameofFile.name;
words=filetoLoad;}
trace(filetoLoad);
return true;



As well, my text output shows "visible non-printing (chr13) characters" instead of 'normal' carriage returns, so that the text comes out in one long line in Notepad but looking 'normal' in MSWord.

Thanks for anything to help.
Reply With Quote
  #2 (permalink)  
Old 05-24-2006, 02:07 PM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re:Opening text files

In text field in flash, "\r" means a new line. However, in notepad, only "\r\n" defined a new line. So before save the text, you would have to first convert it to notepad format:
Code:
myText = myText.replace(/\r/g, "\r\n");
To reload the content of the saved text, you would have to first read its content:

Code:
var stream = new StringStream.readFromFile(filetoload);
var word = stream.toString();
word = word.replace(/\r\n/g, "\r");
FlashPlayer.setVariable("sometext", word);
Reply With Quote
  #3 (permalink)  
Old 05-26-2006, 06:15 AM
Junior Member
 
Join Date: May 2006
Posts: 4
Default Re:Opening text files

Many thanks. I can see the \r\n issue with Notepad now.
However, the load text is still problematic - I'm not certain where to put the code and if anything else is required in the swf other than the textbox with a variable name to reference. I made a basic swf to test: it has one text box (input) called inTxt, with the variable name loadTxt. The fscommand runs the fileOpen script below:

//fileOpen
var txtFile = "Text File (*.txt)|*.txt|";
var filetoLoad = Dialogs.fileOpen(txtFile, "", "", true);
if((filetoLoad!=false) && (File.exists(filetoLoad))){
FlashPlayer.setVariable("_level0.loadTxt",filetoLo ad);
var stream = new StringStream.readFromFile(filetoload);
var txtToLoad = stream.toString();
txtToLoad = txtToLoad.replace(/\r\n/g, "\r");
FlashPlayer.setVariable("_level0.loadTxt",txtToLoa d);}
file_stream.close();
return true;


I'm still missing something as the textbox still stays blank, but I can't see what'ws wrong.
Reply With Quote
  #4 (permalink)  
Old 05-29-2006, 02:13 PM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re:Opening text files

Please send your sample to us, we will help you to make it work.
Reply With Quote
Reply

Was this information helpful?    Yes No



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:43 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.