1 Reply Latest reply on Sep 28, 2009 1:36 PM by Sean_Wilson

    Note Pad Txt


      Can anyone help? I'm trying to create a .txt file using FileIO xtra. Whilst creating the file is relatively easy I have no way of creating more than one line in the txt file. Is there any way I can maintain the formatting from Director to note pad.

        • 1. Re: Note Pad Txt
          Sean_Wilson Adobe Community Professional

          Where is the text you are saving coming from? If it's a #text or #field (or perhaps #flashComponent) member/sprite then you perhaps need to replace the RETURN characters that Director (and MacOS) use to delimit lines for the CRLF character combination that Windows uses as a line delimiter. If it's something you are generating programmatically you can insert the CRLF combo while creating it, or use


          to do this while writing the text to disk line by line (which will be slow and possibly error-prone depending on how much text you're adding).


          Regardless of how you are generating it, you can use a RegEx to pre-process it before writing it to disk. With D10+ you can leverage a single function in a JavaScript movie script:

          function jsStringToDOS (str) {
            return str.replace(/(\x0D)(?!\x0A)/g, "\x0D\x0A");

          To use this function, copy and paste it into a new movie script and make sure the syntax drop-down is set to JavaScript. Then call it by passing it the entire string you wish to write to disk using FileIO:

          -- ...
          tString = member("text entered").text
          tString = jsStringToDOS(tString)
          -- create FileIO object, (create and) open file
          -- check status...
          -- ...



          One more option: if you use the (free) PRegEx xtra you can use it to do the replace AND write your string to disk (I find it much easier to use than FileIO for writing strings to files):

          -- #movie script (Lingo syntax)
          on mWriteDOSString aString, aPath
            l = [aString]
            nReplaced = re_replace(l, "(\x0D)(?!\x0A)", "g", "\x0D\x0A")
            if nReplaced < 0 then alert("Error:" && PRegEx_DescribeError())
            nWritten = re_write(aPath, l)
            if nWritten < 0 then alert("Error:" && PRegEx_DescribeError())
          on mReadDOSString aPath
            tList = re_read(aPath)
            if ilk(tList, #list) = 0 then
              -- error
              alert("Error reading file:" && PRegEx_DescribeError())
            end if
            nReplaced = re_replace(tList, "(\x0D\x0A)", "g", "\x0D")
            if nReplaced < 0 then alert("Error in translation:" && PRegEx_DescribeError())
            return tList[1]