10 Replies Latest reply on Jun 24, 2008 7:43 AM by DarthMarklar

    Reoading Updated Text File (from web)

      I have a project that grabs text from a text file that I have on my server. The code I am using is at the bottom of this post...

      I have a blank cast member called "ClientListImport" and the script works beautifully! - but the problem I have is, when I update the text on the server (via a PHP script), the Director project won't update unless I quit the the projector and re-launch it. I've tried re-running the importFileInto script in the projector, but it won't pull in the new values.

      It's almost as if the text file is either being cached, or re-running the command is just being ignored for some reason. How do I get Director to import the updated text file on my server? Do I need to purge the original text file first?? Can the code only be run the one time??

      Any help would be appreciated.

      Here is the code I am using to insert the text file into my cast member "ClientListImport":
        • 1. Re: Reoading Updated Text File (from web)
          Level 7
          It's probably being cached by Director. You can fool Director by
          supplying a unique parameter to the request (which your server will
          happily ignore):
          tempURL = " http://www.MYWEBSITE.com/ClientListImport.txt"
          tempURL = tempURL & "?i=" & _system.milliseconds
          • 2. Reoading Updated Text File (from web)
            DarthMarklar Level 1
            Sean, thanks for the quick reply, but it doesn't seem to be working. I've even tried something similar where I would set tempURL to something else, then back to the location of the textfile, but it still wouldn't work.
            • 3. Re: Reoading Updated Text File (from web)
              DarthMarklar Level 1
              EDIT: I had to edit out some stuff from my previous post because I ran across some new info that contradicts what I had posted.

              Anyways, I actually did get the cast member to update it's text values from within Director by using the code below, but (of course), while the cast member had been updated with the values from the temp text file, once I tried to reimport the original text file (which I updated), it still brings in the old text.

              So it appears that Director is caching the text from the URL (in memory) and no matter what I do to get the text again, it won't do it and uses what is currently in memory.

              It seems like I need to get it out of memory first before grabbing the newly updated text again.

              • 4. Re: Reoading Updated Text File (from web)
                Level 7
                My advice would be, instead of using importFileInto(), to issue a
                preloadNetThing() against your ("uniqued") URL, wait for it to finish,
                then set the filename of your member to the URL.
                Or, since it's a text file, use getNetText(), again wait for it to
                finish successfully, and set the text of your member to the
                • 5. Re: Reoading Updated Text File (from web)
                  Level 7
                  You didn't say what event is meant to trigger the loading of the file, but
                  the script at
                  http://groups.google.com/group/macromedia.director.lingo/browse_thread/thread/39537a38d373 627e/667f0ca06cacb607?lnk=st&q=#667f0ca06cacb607

                  will do it when attached to something you click on.


                  • 6. Re: Reoading Updated Text File (from web)
                    DarthMarklar Level 1

                    Originally posted by: Newsgroup User
                    You didn't say what event is meant to trigger the loading of the file,

                    I am running a projector file on a PC that displays our clients for that day...since this computer is hidden from site, it's difficult to update the list every morning without breaking the keyboard and mouse out from behind the storage area - (a real pain in the butt)...

                    What I currently have running is, a text file (which contains all of the current clients names) that gets imported into the projector (upon launch) so the receptionist can easily just edit the text file and rerun the projector every morning.

                    Since the computer is hard to get at, what I'm trying to do with the text file is put it on the web and use a PHP script to write the new values to the text file (which I have successfully done)...Then, have the projector import them in everytime it loops through it's animation. This way, no one needs to get into the display computer - we can update it from any system that can access the web.

                    So all I really need is a way to import the text file, but then have the ability to re-import any changes to the text file after it's been updated via the web site. Right now, the changes to the text file won't update in the projector unless I exit out and rerun it. Since this means breaking out the keyboard and mouse again, it defeats the purpose of having the text file on the web site.

                    Andrew, I will look into the link you posted, but it looked confusing to me as to how to implement it into my project.

                    Sean, I will look into the getnettext script, but I'm not 100% up on scripting, so any help would be appreciated.


                    Again, the code below is what I am currently using to import a text file into the cast member "ClientListImport":
                    • 7. Re: Reoading Updated Text File (from web)
                      DarthMarklar Level 1
                      Well, I tried the getNetText() method and it still doesn't get the updated text from the web. The new code I am using is attached below.

                      The other interesting thing is, this:
                      1) I open the program into Director
                      2) I run the timeline (causing the text file to be imported)
                      3) I stop playback in Director, but don't quit out.
                      4) I upload a new text file (to the same URL location) with different values
                      5) I go back into Director and delete the text from the cast member "ClientListImport"
                      6) I then run the timeline again, and it imports the "old" values back into the cast member.

                      Director does appear to be caching the text file in memory and won't allow any new values in unless I exit out first.
                      • 8. Re: Reoading Updated Text File (from web)
                        Level 7
                        > tempURL = getNetText(" http://www.MYWEBSITE.com/ClientListImport.txt")

                        Again: you need to add a dummy query string so that Director doesn't use
                        a cached version

                        netID = getNetText(" http://www.MYWEBSITE.com/ClientListImport.txt?id=" &
                        the milliseconds)

                        > if netDone(netID) then
                        > member("ClientListImport").text = netTextResult(netID)
                        > end if

                        Be aware that you have to loop on a frame waiting for netDone to return
                        TRUE before accessing the netTextResult(). It's possible it's "failing"
                        for you because you skip right past the netTextResult because netDone is

                        -- #movie script:
                        global gNetID

                        on prepareMovie
                        tURL = " http://www.MYWEBSITE.com/ClientListImport.txt?id="
                        tURL = tURL & string(the milliseconds)
                        gNetID = getNetText(tURL)

                        on enterFrame
                        if netDone(gNetID) then
                        if netError(gNetID) = "OK" then
                        member("ClientListImport").text = netTextResult(gNetID)
                        -- propagate whatever other changes are required
                        alert "Error reading text file:" && netError(gNetID)
                        end if
                        end if
                        • 9. Re: Reoading Updated Text File (from web)
                          Level 7
                          Sean's code should do what you need. For completeness sake, you can
                          also try to use the clearcache() command to clear out the cache.
                          • 10. Re: Reoading Updated Text File (from web)
                            DarthMarklar Level 1
                            Thanks again Sean, that script worked.

                            What I also had to do was implement it into a frame script as well so that it would update over and over again. I also combined that with Mike's clearcache() command - Thanks Mike, I was looking for something like that.