Skip to main content
spacebaloon
Known Participant
January 18, 2016
Question

New line return in windows Notepad

  • January 18, 2016
  • 1 reply
  • 1459 views

I have a text field that is populated and shown in my app.

It displays as it should.

I use the \r\n for the mandatory next line. It works fine in the flash app.

Problem is that when I save out the text field to a .txt file, it is all on a single line.

I have tried to use \u000d \u000a as well as  \x0d \x0a with no affect to the text document.

It is in Flash pro cs6 in an Air app.

This topic has been closed for replies.

1 reply

January 19, 2016

What version of AIR are you using? What is your code for saving out the text file?

I made a quick example file testing this and it seems to work fine. I am using Flash CC 2015 and AIR 17.0.0.124 for Desktop and am working on a Mac Pro running Mac OS X 10.10.5 Yosemite. I created a new AIR FLA for desktop, created a dynamic TextField on the stage, gave it an instance name of "textfield_txt", set the text to "this is a bunch of line breaks" with a line break after each word (no spaces). Then I made a new layer and started coding up a File and FileStream objects to save the text from the TextField to an existing ".txt" text file on my desktop named "lineBreaks.txt". When my TextField was NOT set to Multiline for the "Behavior" property under "Paragraph" options in the Properties inspector, it rendered everything together as one long run on word. When I changed it to Multiline, it wrote to the .txt file with the line breaks. Here is my code:

import flash.events.Event;

import flash.events.IOErrorEvent;

import flash.filesystem.File;

import flash.filesystem.FileMode;

import flash.filesystem.FileStream;

import flash.text.TextField;

var textfield_txt:TextField;

var textFile:File = File.desktopDirectory;

textFile = textFile.resolvePath("lineBreaks.txt");

var fs:FileStream = new FileStream();

fs.open(textFile, FileMode.WRITE);// open for writing to the text file

fs.writeUTFBytes(textfield_txt.text);// write the .text String from the TextField into the File

fs.close();// close FileStream and then setup listeners for opening back up and reading new text data

fs.addEventListener(Event.COMPLETE, onFileLoaded);

fs.addEventListener(IOErrorEvent.IO_ERROR, onFileLoadFail);

fs.openAsync(textFile, FileMode.READ);// regular .open() doesn't seem to dispatch Event.COMPLETE for knowing it is ready for reading

function onFileLoaded(e:Event):void {

  trace(fs.readUTFBytes(fs.bytesAvailable));

}

function onFileLoadFail(e:IOErrorEvent):void {

  trace(e.toString());

}

spacebaloon
Known Participant
January 19, 2016

HI

I am working in Windows 10 pro and using Air 3.4 for desktop. It is the latest version available to me.

For clarification, this is for the base text program in windows. Which is Notepad.

If I open in another program that has more power, such as WordPad or OpenOffice it displays fine.

Also if I save a txt file from any text editing program and then open it in Notepad, it reads fine.

So I would conclude that it is the write engine in flash.

Here is my code that I am using.

    import flash.filesystem.*;     

    import flash.events.Event;

    function onSave(event:Event):void {

    var file:File=File.applicationStorageDirectory;     

    file=file.resolvePath("TEMP directory/"+  title_txt.text +"/"+  title_txt.text +".txt");     

    var fileStream:FileStream = new FileStream();     

      fileStream.open(file, FileMode.WRITE);     

      fileStream.writeUTFBytes(result_txt.text + "");     

      fileStream.addEventListener(Event.CLOSE, fileClosed);     

      fileStream.close();   

    function fileClosed(event:Event):void {         

     trace("closed event fired");     

    }

   }

January 19, 2016

Interesting. I don't see anything wrong with what you have from a functionality standpoint. Is the AIR 3.4 a company limitation or are there other reasons for not using the newest version of AIR?