20 Replies Latest reply on Jan 24, 2008 5:00 PM by Newsgroup_User

    Creating a .txt

    rafa@mediatech Level 1
      Hello everyone:
      Is there a way that I can create a notepad file from a Director screen? I have a project that reads lines from a notepad and then fills different text members inside my .exe. I want to create a new .exe that the user can open, imput information needed inside blank text fields, and then he hits create (or submit), then a notepad file (.txt) is created and saved somewhere so that the other .exe can read it and fill in his text fields.
      I would need to be able to be specific on which line of the notepad the data entered by the user is saved, because the other .exe reads lines specifically.

      Thank you,

      Rafael.
        • 1. Re: Creating a .txt
          Level 7
          Easily accomplished using the fileIO xtra included with director.

          http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_3192&sliceId=2





          rafa@mediatech wrote:
          > Hello everyone:
          > Is there a way that I can create a notepad file from a Director screen? I have
          > a project that reads lines from a notepad and then fills different text members
          > inside my .exe. I want to create a new .exe that the user can open, imput
          > information needed inside blank text fields, and then he hits create (or
          > submit), then a notepad file (.txt) is created and saved somewhere so that the
          > other .exe can read it and fill in his text fields.
          > I would need to be able to be specific on which line of the notepad the data
          > entered by the user is saved, because the other .exe reads lines specifically.
          >
          > Thank you,
          >
          > Rafael.
          >
          • 2. Re: Creating a .txt
            rafa@mediatech Level 1
            Dave:
            Thanks for replying. I did find that adobe link, and it answer one of my questions. But like I mentioned on my post, i need to be able to have the information appear in different lines. Ex:

            name (line 1 of notepad)
            email (line 2 of notepad)
            phone (line 3 of notepad)

            With the example on the adobe page, hitting enter to go to the next line, doesnt break a line on the notepad itself, it just gives me a weird symbol. How can I be line specific on the output information?

            Thank you.

            • 3. Re: Creating a .txt
              Level 7
              This is on a Windows OS, right?

              Before you write your string to the file, you need to replace all of the
              Director "Return" characters with numToChar(13) & numToChar(10).

              Do you know how to do that?



              rafa@mediatech wrote:
              > Dave:
              > Thanks for replying. I did find that adobe link, and it answer one of my
              > questions. But like I mentioned on my post, i need to be able to have the
              > information appear in different lines. Ex:
              >
              > name (line 1 of notepad)
              > email (line 2 of notepad)
              > phone (line 3 of notepad)
              >
              > With the example on the adobe page, hitting enter to go to the next line,
              > doesnt break a line on the notepad itself, it just gives me a weird symbol. How
              > can I be line specific on the output information?
              >
              > Thank you.
              >
              >
              >
              • 4. Re: Creating a .txt
                Level 7
                There may certainly be more elegant solutions, but I typically create a
                movie script like this (be careful of the unintended line breaks being
                inserted by the newsreader)

                on prepareStringForFileWrite inputString
                returnString = ""
                repeat with i = 1 to inputString.line.count
                if returnString <> "" then returnString = returnString &
                numToChar(13) & numToChar(10)
                returnString = returnString & inputString.line
                end repeat
                return returnString
                end


                so if the text you want to write is in a variable, pass it to the
                function before writing.

                myTextVar = prepareStringForFileWrite(myTextVar)
                • 5. Re: Creating a .txt
                  rafa@mediatech Level 1
                  Dave:
                  It is for windows. So this would work for having different input fields, right?
                  on the adobe sample it only shows using the text member "input", I will have at 3-5 different input fields. I guess I can use the same save code:

                  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 &"info.txt",0)--Open the file with R/W access
                  delete(myFile) --deletes the file
                  createFile (myFile, the moviePath &"info.txt") --creates the file again
                  openFile(myFile,the moviePath &"info.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

                  And in the section where it says mySaveString = member("input").text
                  I will just add the names of the other fields i have, correct?

                  Where would I add the "return" code you mention above?
                  • 6. Re: Creating a .txt
                    Level 7
                    By the way, this problem is primarily restricted to opening the text
                    file (that you created with director) with Windows notepad. Try opening
                    the same file (with those funny squares) in Wordpad, you will see the
                    file displays just fine.

                    Want to see something really funny? Create a file using notepad with
                    just this text in it

                    this app can break

                    Save it and close it. Then open it with notepad again. Cure huh? Now
                    open it with wordpad. The bottom line, notepad basically sucks and the
                    developers knew it.
                    • 7. Re: Creating a .txt
                      Level 7
                      If you add the movie script that I gave you, then just replace this line
                      of your code

                      mySaveString = member("input").text

                      with this

                      mySaveString = prepareStringForFileWrite(member("input").text)
                      • 8. Re: Creating a .txt
                        Level 7
                        mySaveString = member("input").text & return & member("inputLine2").text
                        & return & member("inputLine4").text

                        <Watch for inadvertent line breaks... that should all be on one single line>
                        • 9. Re: Creating a .txt
                          rafa@mediatech Level 1
                          Dave it works, the notepad is taking the information from my text fields, but it is not doing the line brake, it just gives me the weird symbol. I did what you suggested, I opened the same file in word pad, and it does keep the line breaks, WEIRD!

                          I placed the code you gave me on a time line script on enterFrame me, do I have to put it on the "save" button?
                          • 10. Re: Creating a .txt
                            Level 7
                            No, the prepareStringForFileWrite should be a movie script so that it
                            can be called from anywhere.

                            You could put it in the save button (assuming this is where you mouseUp
                            handler is) and it will work. But if you put it in a movie script then
                            you can call it from any other handler as needed.


                            rafa@mediatech wrote:
                            > Dave it works, the notepad is taking the information from my text fields, but
                            > it is not doing the line brake, it just gives me the weird symbol. I did what
                            > you suggested, I opened the same file in word pad, and it does keep the line
                            > breaks, WEIRD!
                            >
                            > I placed the code you gave me on a time line script on enterFrame me, do I
                            > have to put it on the "save" button?
                            >
                            • 11. Re: Creating a .txt
                              Level 7
                              No, the prepareStringForFileWrite should be a movie script so that it
                              can be called from anywhere.

                              You could put it in the save button (assuming this is where you mouseUp
                              handler is) and it will work. But if you put it in a movie script then
                              you can call it from any other handler as needed.



                              rafa@mediatech wrote:
                              > Dave it works, the notepad is taking the information from my text fields, but
                              > it is not doing the line brake, it just gives me the weird symbol. I did what
                              > you suggested, I opened the same file in word pad, and it does keep the line
                              > breaks, WEIRD!
                              >
                              > I placed the code you gave me on a time line script on enterFrame me, do I
                              > have to put it on the "save" button?
                              >
                              • 12. Re: Creating a .txt
                                rafa@mediatech Level 1
                                Hey Dave:
                                Also, I changed all the extensions on the adobe code to be info.rtf. When I hit save, it does create a .rtf file. Let see if I can get my other project to read from the .rtf and make it work. Any issues you can think of that I might encounter using FileIo to create .rtf files?
                                • 13. Re: Creating a .txt
                                  Level 7
                                  Simply changing the file extension to .rtf does not make it an rtf
                                  file... you are making a standard text file that has an rtf extension.
                                  It will make it so that when you double click it in Windows, Wordpad
                                  will open, and Wordpad can read text files just fine, regardless of the
                                  extension. But you may end up with problems later on if someone saves
                                  the file as an actual rtf, and your application will not be able to
                                  handle it... also, if someone has changed the default application to
                                  open rtfs, then there may be problems there as well.
                                  • 14. Re: Creating a .txt
                                    Level 7
                                    Like Mike said, you aren't really creating a rtf file.

                                    What is your purpose of naming the file you create as info.rtf?


                                    rafa@mediatech wrote:
                                    > Hey Dave:
                                    > Also, I changed all the extensions on the adobe code to be info.rtf. When I
                                    > hit save, it does create a .rtf file. Let see if I can get my other project to
                                    > read from the .rtf and make it work. Any issues you can think of that I might
                                    > encounter using FileIo to create .rtf files?
                                    >
                                    • 15. Re: Creating a .txt
                                      rafa@mediatech Level 1
                                      I don't need the file to be an rtf, I actually needed to be a .txt. I changed it because, as Dave mentioned, rtf was keeping the line breaks. The way my other project reads .txt. it needs to have the info broken into lines.

                                      I guess I was worried about the .txt coming out with the weird square symbols and thought this would affect how my project reads from it.
                                      • 16. Re: Creating a .txt
                                        Level 7
                                        You are incorrect when you say that "rtf was keeping the line breaks".
                                        That is not what is happening. All that is happening is that saving the
                                        file with an rtf extension causes Wordpad to open it by default instead
                                        of Notepad. And wordpad does not show the squares instead of line
                                        breaks. The same thing could be said if you set the filename to *.doc.
                                        Then it would open in Word, but it would NOT actually be a word doc,
                                        and though Word would open it without complaint, you would be causing
                                        unnecessary problems by incorrectly labeling your file.

                                        Dave's prepareStringForFileWrite() handler is exactly what you should be
                                        using. That will let you save a text file with the correct .txt
                                        extension, and it will have line breaks like it ought to have. The way
                                        you put things on different lines is done like I showed earlier.

                                        mySaveString = member("input").text & return & member("inputLine2").text
                                        & return & member("inputLine4").text

                                        <watch for line breaks - that should be 1 line of code>

                                        once you have your save string built, you can put it through Dave's code:

                                        mySaveString=prepareStringForFileWrite(mySaveString)

                                        Then you can save it out to a text file (labeled .txt) and it will
                                        appear correct when you open it in notepad or anything else.
                                        • 17. Re: Creating a .txt
                                          Level 7
                                          Rafa, I am afraid I have confused you. I will try to explain.

                                          Notepad expects to see two characters indicating the end of line: the
                                          carraige return (CR) character and the line feed (LF) character.

                                          The Director character RETURN is only the CR character. So when you
                                          write a text file with director consisting of multiple lines, and then
                                          open it with notepad, notepad does not interpret the CR correctly
                                          (remember notepad is pretty lame). Since CR is a nonprintable character
                                          it uses the little square to indicate there is a non printable character
                                          there (the CR).

                                          The code I gave you basically added the LF to the end of each line. All
                                          that does is make the file more human readable in Notepad. It is
                                          completely unnecessary to do this if you don't care about making the
                                          file easy for humans to read.

                                          If you read into Director a file with just the CR (the little squares)
                                          it will work as expected. Director sees the CR and makes a new line as
                                          expected.

                                          There is really no need for you to change anything from the way you had
                                          it to start with. You have one program already writing your data to a
                                          file. Your other program should read it in just fine. The little squares
                                          won't mess it up, in fact Director will know that those squares indicate
                                          a new line.
                                          • 18. Re: Creating a .txt
                                            Level 7
                                            > Then you can save it out to a text file (labeled .txt) and it will
                                            > appear correct when you open it in notepad or anything else.

                                            I finally figured out what he want to do. He is going to be reading the
                                            file into another Director app, so if he uses my code (appends the LF)
                                            and writes the file, then he will just have to strip the LF character
                                            out in the app that reads the file.

                                            No real point in that, unless he just wants to make reading the file in
                                            notepad easy.
                                            • 19. Re: Creating a .txt
                                              rafa@mediatech Level 1
                                              Wow!! you guys are awesome!!
                                              Sorry I wasn't clear about my end use for the .txt file that I needed to create. It does not need to be user friendly, I only need my other .exe to be able to use the information found on the .txt and fill in the correct text fields inside the .exe.

                                              I greatly appreciate the time and effort you guys have put in to help me with my problem.

                                              Rafael.
                                              • 20. Re: Creating a .txt
                                                Level 7
                                                I myself am greatly indebted to the help given on this forum.

                                                Transferring data between director movies via text files is fine for
                                                many applications. However there are other interesting ways to transfer
                                                data between movies that have some advantages. Movies in a window,
                                                Linked Director Movie, MUS xtra...