|
|||
|
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. |
|
|||
|
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"); Code:
var stream = new StringStream.readFromFile(filetoload);
var word = stream.toString();
word = word.replace(/\r\n/g, "\r");
FlashPlayer.setVariable("sometext", word);
|
|
|||
|
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. |
![]() |
Was this information helpful? Yes No
| Thread Tools | |
| Display Modes | |
|
|