4 Replies Latest reply on Nov 24, 2010 10:59 AM by Hosseinrostamzadeh

    problem with formatting the saved text to hard disk

    Hosseinrostamzadeh

      I use a modified code from Macromedia for saving the content of a text filed on hard disk. See code at the end.

       

      The code works fine and a text file is saved in the given location on the hard disk.

      The problem is that all of the content of the text field appears in a very long single line.

      The line breaks in the text field does not appear at all in the saved text file.

      for example:

      if the following is the the content of the text filed on the stage:

      abcdef

      jhijklm

      nopqrst

      uvxwyz 

      then the saved file is like: abcdefjhijklmnopqrstuvxwyz 

       

      No line break happens! How can this be fixed?

      Thanks for any suggestions.

      HR

       

      ******************* Here is the code *************************

      ----------------------------------------------------------------------------------
      --this handler saves the contents of the field into a text file called 'output.txt'
      --it over writes anything that is in the 'output.txt' file.
      ----------------------------------------------------------------------------------

       

      global myFile

       

      on mouseUp
       
        if objectP(myFile) then set myFile = 0  --Delete the instance if it already exists
       
        myFile = new(xtra "fileio")    -- Create an instance of FileIO
       
        openFile (myFile, the moviePath &"output.txt",0)--Open the file with R/W access
       
        delete(myFile) --deletes the file
       
        createFile (myFile, the moviePath &"output.txt) --creates the file again
       
        openFile(myFile,the moviePath &"output.txt,0) --Open the file with R/W access
       
        mySaveString = member("input").text --puts the contents of the field 'input' into the variable mySaveString
       
        writeString(myFile,mySaveString) --writes text to the file
       
        closeFile(myFile) -- Close the file
       
        myFile = 0 -- Dispose of the instance
       
      end

       

       

       

      ******************

        • 1. Re: problem with formatting the saved text to hard disk
          Sean_Wilson Adobe Community Professional

          You need to replace the carriage returns (that aren't followed by a line feed) with the CRLF combination. Feel free to place the following JavaScript handler into a movie script and call it prior to writing your string to disk:

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

           

          global myFile
          
          on mouseUp
            if objectP(myFile) then set myFile = 0  --Delete the instance if it already exists
            myFile = new(xtra "fileio")    -- Create an instance of FileIO
            openFile (myFile, the moviePath &"output.txt",0)--Open the file with R/W access
            delete(myFile) --deletes the file
            createFile(myFile, the moviePath &"output.txt") --creates the file again
            openFile(myFile,the moviePath &"output.txt",0) --Open the file with R/W access
            mySaveString = member("input").text --puts the contents of the field 'input' into the variable mySaveString
            mySaveString = jsStringToDOS(mySaveString) -- convert to Windows CRLF characters
            writeString(myFile,mySaveString) --writes text to the file
            closeFile(myFile) -- Close the file
            myFile = 0 -- Dispose of the instance
          end
          
          • 2. Re: problem with formatting the saved text to hard disk
            Hosseinrostamzadeh Level 1

            Thanks for your answer!

            But I tried it, I get error in compiling.

            It apparently does not understand both lingo( all code written) and java script(your code) at the same movie.

             

            But I have changed the file extension in output file (to be written on disk) fra .txt to .odt(open office text document).

            Then when I open the output.odt file in open office writer then before it opens the file it asks if the section separator is CR or CRLF and i choose CR.

            Then its works as predicted. Alle line breaks appears where they exist in input-text field.

            I tried it with .doc extension it works too! It seems that the problem happens in txt file format It was discovered only by luck!

             


            Best regards!

            HR.

            • 3. Re: problem with formatting the saved text to hard disk
              Sean_Wilson Adobe Community Professional

              So your problem is fixed?

               

              In order to get the JS handler/function to compile, it needs to go into a script member whose scriptSyntax is JavaScript. There is a drop-down at the top-left of the script window that allows you to change this. For that reason, the JS function should go into a separate #movie script with the scriptSyntax set accordingly

              • 4. Re: problem with formatting the saved text to hard disk
                Hosseinrostamzadeh Level 1

                Thank you Sean!

                great help, yes the problem is fixednow.

                Best regards!

                HR