15 Replies Latest reply on Nov 5, 2006 9:54 AM by Newsgroup_User

    FileIO

    Lakerol
      Hello everybody,

      I have a director movie with a field, called "input", and I want everything in this field, to be saved into "info.txt"..
      So I have a button "save" with this code:

      global myFile
      on mouseUp
      if objectP(myFile) then set myFile = 0 myFile = new(xtra "fileio")
      openFile (myFile, the moviePath &"info.txt",0)
      delete(myFile)
      createFile (myFile, the moviePath &"info.txt")
      openFile(myFile,the moviePath &"info.txt",0)
      mySaveString = member("input").text
      writeString(myFile,mySaveString)
      closeFile(myFile)
      myFile = 0

      end


      and a button "open" with this code:

      global myFile
      on mouseUp
      if objectP(myFile) then set myFile = 0
      myFile = new(xtra "fileio")
      openFile(myFile,the moviePath&"info.txt",1)
      myVariable = readFile(myFile)
      if readFile(myFile)=VOID then
      alert "NOTHING HAS EVER BEEN SAVED"
      else
      member("input").text = myVariable
      closeFile(myFile)
      end if
      myFile = 0
      end

      But director everytime I push the "open" button, keeps displaying that nothing has been saved yet..

      Can somebody help me please?
        • 1. Re: FileIO
          Level 7
          I'm not sure if you have two pieces of code on the same line because of
          cutting and pasting or if that's the way you wrote it but the following
          worked for me.

          I put these in a movie script so I wouldn't have to go through creating a
          button but that should make no difference. I just triggered them from the
          message window and it worked fine.


          global myFile

          on writeIt
          if objectP(myFile) then set myFile = 0
          myFile = new(xtra "fileio")
          openFile (myFile, the moviePath &"info.txt",0)
          delete(myFile)
          createFile (myFile, the moviePath &"info.txt")
          openFile(myFile,the moviePath &"info.txt",0)
          mySaveString = member("input").text
          writeString(myFile,mySaveString)
          closeFile(myFile)
          myFile = 0

          end


          --and a button "open" with this code:

          on ReadIt
          if objectP(myFile) then set myFile = 0
          myFile = new(xtra "fileio")
          openFile(myFile,the moviePath&"info.txt",1)
          myVariable = readFile(myFile)
          if readFile(myFile)=VOID then
          alert "NOTHING HAS EVER BEEN SAVED"
          else
          member("input").text = myVariable
          closeFile(myFile)
          end if
          myFile = 0
          end


          --
          Craig Wollman
          Word of Mouth Productions

          phone 212 928 9581
          fax 212 928 9582
          159-00 Riverside Drive West #5H-70
          NY, NY 10032
          www.wordofmouthpros.com


          "Lakerol" <webforumsuser@macromedia.com> wrote in message
          news:ei58qk$ck8$1@forums.macromedia.com...
          > Hello everybody,
          >
          > I have a director movie with a field, called "input", and I want
          > everything in
          > this field, to be saved into "info.txt"..
          > So I have a button "save" with this code:
          >
          > global myFile
          > on mouseUp
          > if objectP(myFile) then set myFile = 0 myFile = new(xtra "fileio")
          > openFile (myFile, the moviePath &"info.txt",0)
          > delete(myFile)
          > createFile (myFile, the moviePath &"info.txt")
          > openFile(myFile,the moviePath &"info.txt",0)
          > mySaveString = member("input").text
          > writeString(myFile,mySaveString)
          > closeFile(myFile)
          > myFile = 0
          >
          > end
          >
          >
          > and a button "open" with this code:
          >
          > global myFile
          > on mouseUp
          > if objectP(myFile) then set myFile = 0
          > myFile = new(xtra "fileio")
          > openFile(myFile,the moviePath&"info.txt",1)
          > myVariable = readFile(myFile)
          > if readFile(myFile)=VOID then
          > alert "NOTHING HAS EVER BEEN SAVED"
          > else
          > member("input").text = myVariable
          > closeFile(myFile)
          > end if
          > myFile = 0
          > end
          >
          > But director everytime I push the "open" button, keeps displaying that
          > nothing
          > has been saved yet..
          >
          > Can somebody help me please?
          >
          >


          • 2. Re: FileIO
            Lakerol Level 1
            Thanks a lot Craig..

            Now I have another problem:
            The file that can be entered in de input field, can only start with the words "mail" or "phone", this works fine but..
            There's a button on stage which says "phone", when pushed this, the input field can only display the sentences beginning with "phone"

            Anybody any idea?
            • 3. Re: FileIO
              Lakerol Level 1
              I already found this:

              global myFile
              on mousedown me
              if not objectP(myFile) then myFile = new (xtra "FileIO")
              openFile(myFile,the moviePath&"info.txt",1)
              myVariable = readFile(myFile)
              closeFile(myFile)

              tempString = "Sorry - geen entries gevonden"

              repeat with i = 1 to the number of lines of myVariable
              if (word 1 of line i of myVariable = "phone" ) then
              tempString = line i of myVariable
              end if
              end repeat


              member("lijstVeld").text = tempString

              myFile = 0
              end


              But now I only get 1 item displayed beginning with "phone", though there are more items beginning with "phone" in myVariable
              Because tempString gets overwritten everytime... But I can't think of a way to solve this
              • 4. Re: FileIO
                duckets Level 1
                how about this:

                tempString = tempString & line i of myVariableline i of myVariable & RETURN

                I have added the 'RETURN' value so that each line appears on a new line within the tempString variable.

                hope this helps,

                - Ben
                • 5. Re: FileIO
                  Level 7
                  Now that will give you an error every time.

                  This was tested. You can go crazy making your code bullet proof but
                  typically you'd want to check for a line feed or CR at the end of a line so
                  you and add or not add a RETURN character so your text is formatted the way
                  you want. But for now, I'm guessing your text file will have CR's
                  separating the lines so this code is fine for now. I made it a bit more
                  modern by using dot syntax. I hope this doesn't confuse you. I also added
                  a few local variables to reduce the load on each line. This is good for
                  debugging so that you can see the values of individual items. You can't do
                  this when you put multiple functions on each line.

                  global myFile

                  on mouseDown me
                  if not objectP(myFile) then myFile = new (xtra "FileIO")
                  openFile(myFile,the moviePath&"info.txt",1)
                  myVariable = readFile(myFile)
                  closeFile(myFile)

                  tempString = "Sorry - geen entries gevonden"

                  cnt = myVariable.line.count
                  repeat with i = 1 to cnt
                  nextLine = myVariable.line
                  nextWordCheck = nextLine.word [1]
                  if nextWordCheck = "phone" then
                  tempString = tempString & nextLine
                  end if
                  end repeat


                  member("lijstVeld").text = tempString

                  myFile = 0
                  end


                  --
                  Craig Wollman
                  Word of Mouth Productions

                  phone 212 928 9581
                  fax 212 928 9582
                  159-00 Riverside Drive West #5H-70
                  NY, NY 10032
                  www.wordofmouthpros.com


                  "duckets" <webforumsuser@macromedia.com> wrote in message
                  news:ei7d7o$s4$1@forums.macromedia.com...
                  > how about this:
                  >
                  > tempString = tempString & line i of myVariableline i of myVariable &
                  > RETURN
                  >
                  > I have added the 'RETURN' value so that each line appears on a new line
                  > within
                  > the tempString variable.
                  >
                  > hope this helps,
                  >
                  > - Ben
                  >
                  >


                  • 6. Re: FileIO
                    Level 7
                    By the way, if your text file has lines and CR's you'll get double spacing
                    if you use the RETURN.

                    As I mentioned in my previous post, check for a RETURN and adding one if it
                    isn't there is more effective to control line spacing.

                    --
                    Craig Wollman
                    Word of Mouth Productions

                    phone 212 928 9581
                    fax 212 928 9582
                    159-00 Riverside Drive West #5H-70
                    NY, NY 10032
                    www.wordofmouthpros.com


                    "duckets" <webforumsuser@macromedia.com> wrote in message
                    news:ei7d7o$s4$1@forums.macromedia.com...
                    > how about this:
                    >
                    > tempString = tempString & line i of myVariableline i of myVariable &
                    > RETURN
                    >
                    > I have added the 'RETURN' value so that each line appears on a new line
                    > within
                    > the tempString variable.
                    >
                    > hope this helps,
                    >
                    > - Ben
                    >
                    >


                    • 7. FileIO
                      Lakerol Level 1

                      Thanks a lot Craig!
                      But this gives me an error that says "property not found" referring to this line "nextLine = myVariable.line"

                      quote:

                      Originally posted by: Newsgroup User

                      global myFile

                      on mouseDown me
                      if not objectP(myFile) then myFile = new (xtra "FileIO")
                      openFile(myFile,the moviePath&"info.txt",1)
                      myVariable = readFile(myFile)
                      closeFile(myFile)

                      tempString = "Sorry - geen entries gevonden"

                      cnt = myVariable.line.count
                      repeat with i = 1 to cnt
                      nextLine = myVariable.line
                      nextWordCheck = nextLine.word [1]
                      if nextWordCheck = "phone" then
                      tempString = tempString & nextLine
                      end if
                      end repeat


                      member("lijstVeld").text = tempString

                      myFile = 0
                      end





                      • 8. Re: FileIO
                        Level 7
                        It didn't for me. Did you copy and paste my code? I'm assuming you typed
                        it since you have a capital I in that line.

                        Do you know how to use the debugger? That will allow you to see the value
                        of myVariable to make sure it has text in it although as long as it's a
                        string it shouldn't matter. I can't imagine case matters but you might want
                        to change that I to an i


                        --
                        Craig Wollman
                        Word of Mouth Productions

                        phone 212 928 9581
                        fax 212 928 9582
                        159-00 Riverside Drive West #5H-70
                        NY, NY 10032
                        www.wordofmouthpros.com


                        "Lakerol" <webforumsuser@macromedia.com> wrote in message
                        news:ei7l9s$aan$1@forums.macromedia.com...
                        >
                        quote:

                        Originally posted by: Newsgroup User
                        >
                        > global myFile
                        >
                        > on mouseDown me
                        > if not objectP(myFile) then myFile = new (xtra "FileIO")
                        > openFile(myFile,the moviePath&"info.txt",1)
                        > myVariable = readFile(myFile)
                        > closeFile(myFile)
                        >
                        > tempString = "Sorry - geen entries gevonden"
                        >
                        > cnt = myVariable.line.count
                        > repeat with i = 1 to cnt
                        > nextLine = myVariable.line
                        > nextWordCheck = nextLine.word [1]
                        > if nextWordCheck = "phone" then
                        > tempString = tempString & nextLine
                        > end if
                        > end repeat
                        >
                        >
                        > member("lijstVeld").text = tempString
                        >
                        > myFile = 0
                        > end
                        >
                        >
                        >


                        >
                        > Thanks a lot Craig!
                        > But this gives me an error that says "property not found" referring to
                        > this
                        > line "nextLine = myVariable.line"
                        >
                        >


                        • 9. Re: FileIO
                          Level 7
                          I just tried YOUR code from your last posting and it worked fine. Maybe
                          you're not reading in the file properly or you move the file.


                          --
                          Craig Wollman
                          Word of Mouth Productions

                          phone 212 928 9581
                          fax 212 928 9582
                          159-00 Riverside Drive West #5H-70
                          NY, NY 10032
                          www.wordofmouthpros.com


                          "Lakerol" <webforumsuser@macromedia.com> wrote in message
                          news:ei7l9s$aan$1@forums.macromedia.com...
                          >
                          quote:

                          Originally posted by: Newsgroup User
                          >
                          > global myFile
                          >
                          > on mouseDown me
                          > if not objectP(myFile) then myFile = new (xtra "FileIO")
                          > openFile(myFile,the moviePath&"info.txt",1)
                          > myVariable = readFile(myFile)
                          > closeFile(myFile)
                          >
                          > tempString = "Sorry - geen entries gevonden"
                          >
                          > cnt = myVariable.line.count
                          > repeat with i = 1 to cnt
                          > nextLine = myVariable.line
                          > nextWordCheck = nextLine.word [1]
                          > if nextWordCheck = "phone" then
                          > tempString = tempString & nextLine
                          > end if
                          > end repeat
                          >
                          >
                          > member("lijstVeld").text = tempString
                          >
                          > myFile = 0
                          > end
                          >
                          >
                          >


                          >
                          > Thanks a lot Craig!
                          > But this gives me an error that says "property not found" referring to
                          > this
                          > line "nextLine = myVariable.line"
                          >
                          >


                          • 10. Re: FileIO
                            Lakerol Level 1
                            Thanks Craig now it works fine.
                            Is there a way to start this application automatically when the computer is started?
                            • 11. Re: FileIO
                              Level 7
                              Yes, instead of using a mouse event script put it in a movie script
                              (CNT-SHIFT-u) and give it a name other than a Lingo event, i.e. don't call
                              it on exitFrame or on mouseEnter etc, call it, on GetTextFromFile or
                              something like that.

                              Then in the same script window add a StartMovie script that calls the above
                              named handler.

                              Or you could put it in an exitFrame script in frame 2 (as long as the
                              playback head doesn't repeat on frame 2


                              --
                              Craig Wollman
                              Word of Mouth Productions

                              phone 212 928 9581
                              fax 212 928 9582
                              159-00 Riverside Drive West #5H-70
                              NY, NY 10032
                              www.wordofmouthpros.com


                              "Lakerol" <webforumsuser@macromedia.com> wrote in message
                              news:eiaifk$qgb$1@forums.macromedia.com...
                              > Thanks Craig now it works fine.
                              > Is there a way to start this application automatically when the computer
                              > is started?


                              • 12. Re: FileIO
                                Lakerol Level 1
                                Craig, could you send me your e-mailaddress by private message so I can e-mail you my Director movie, and then you can see how it looks like now..
                                • 13. Re: FileIO
                                  Level 7
                                  I'd be happy to help you here only. Feel free to post other issues you're
                                  having and I'll respond.

                                  Craig


                                  --
                                  Craig Wollman
                                  Word of Mouth Productions

                                  phone 212 928 9581
                                  fax 212 928 9582
                                  159-00 Riverside Drive West #5H-70
                                  NY, NY 10032
                                  www.wordofmouthpros.com


                                  "Lakerol" <webforumsuser@macromedia.com> wrote in message
                                  news:eib08h$dcs$1@forums.macromedia.com...
                                  > Craig, could you send me your e-mailaddress by private message so I can
                                  > e-mail you my Director movie, and then you can see how it looks like now..
                                  >


                                  • 14. Re: FileIO
                                    Lakerol Level 1
                                    I have discovered a new problem when placing this movie on the internet.
                                    Remember where we wrote the script for viewing items of a category, this one:
                                    > global myFile
                                    >
                                    > on mouseDown me
                                    > if not objectP(myFile) then myFile = new (xtra "FileIO")
                                    > openFile(myFile,the moviePath&"info.txt",1)
                                    > myVariable = readFile(myFile)
                                    > closeFile(myFile)
                                    >
                                    > tempString = "Sorry - geen entries gevonden"
                                    >
                                    > cnt = myVariable.line.count
                                    > repeat with i = 1 to cnt
                                    > nextLine = myVariable.line
                                    > nextWordCheck = nextLine.word [1]
                                    > if nextWordCheck = "phone" then
                                    > tempString = tempString & nextLine
                                    > end if
                                    > end repeat
                                    >
                                    >
                                    > member("lijstVeld").text = tempString
                                    >
                                    > myFile = 0
                                    > end


                                    But on the internet this doesn't work. Maybe something's wrong with this:
                                    "openFile(myFile,the moviePath&"info.txt",1)" ?
                                    • 15. Re: FileIO
                                      Level 7
                                      the FileIO xtra is not shockwave safe, so you can not use it or any of
                                      it's functions in Shockwave in a browser.