14 Replies Latest reply on Aug 15, 2008 2:32 PM by farazfo

    save/load variables online

    farazfo
      I want to simply save some variables in a text file as strings.
      and load theme when I need them.
      I want to do this online
      I tried FileIO Xtra but when I started the .dcr file in web page this error ocures:
      "This Shockwave movie has errors that caused playback problems.
      Please contact the author of this content regarding this program.
      Shockwave is unable to continue."
      I could not fix this error and use FileIO Xtra in .dcr file
      is it possible to use this Xtra? if its possible how should i do this?!
      I used netlingo Xtra too and i could load an text file by getnettext() command
      but i could not use postnettext() if its not possible to use FileIO Xtra online please help me to use postnettext tu save text file
      thanx.
        • 1. save/load variables online
          pete.h
          The FileIO Xtra is not Shockwave-safe, so no, you won't be able to use it.

          Take a look at the Director help, searching for the setPref and getPref commands.

          Or you could use a Flash Shared Object to save name/value pairs on the local machine, via the Flash Asset Xtra. Check out this article here: http://director-online.com/buildArticle.php?id=1082
          • 2. Re: save/load variables online
            Level 7
            pete.h posted in macromedia.director.lingo:

            > The FileIO Xtra is not Shockwave-safe, so no, you won't be able to use it.
            >
            > You could use a Flash Shared Object to save name/value pairs on the local
            > machine, via the Flash Asset Xtra. Check out this article here:
            > http://director-online.com/buildArticle.php?id=1082

            Also for saving to the local system, there is setPref/getPref

            (If you have a Mac, you might want to follow up on bmashford's setpref
            question in this group on July 26)


            --
            Mark A. Boyd
            Keep-On-Learnin' :)
            • 3. Re: save/load variables online
              ensamblador Level 1
              If you need (in a web page) to save/load a file from a specific place (not default, not cookies, not setpref, not shared object, not sessions) in the local machine the user must be prompted to save/load that file. Threre is no other way.

              I found a way to achieve that by using lingo+flash+server scripting. Basically I have a swf in the same page of the dcr, then I create a localconnection between dcr and swf, so I can use the fileReference Object inside flash.

              In this case I used PHP to code a download/upload file script. The basic algorith is:

              To save:

              1.-Store the variables in a string then send those vars to flash (via localcon).
              2.-in flash use a filereference object to prompt for a save location.
              3.-using the same object send the vars to save.php scritp using POST or GET.
              4.-in php create the file (on the fly) give it to flash.

              To Load:
              1.-send the instruction to flash to load a file (again, using localconnection)
              2.-inside flash, use file reference to select the file to load.
              3.-send the file to load to load.php
              4.-in php, read the file and return the contents as a text response,
              5.-In flash receive this response and forward to showckwave (using local, connection)

              Is that what you want to do?.

              • 4. Re: save/load variables online
                farazfo Level 1
                hi...
                thank you for you answer...
                helped so much
                thank you for th external article...
                I want to save the data on the website not in the user's hard drive
                can you help me more please?...
                • 5. Re: save/load variables online
                  farazfo Level 1
                  thank you "ensamblador " for your complete explain
                  your suggestion is perfect
                  but its very professional... i'm a begginer i cant du this...
                  can you help me to do this in a simple way?
                  I just want tu save some variables on my website some thing like a very simple and small database
                  • 6. Re: save/load variables online
                    ensamblador Level 1
                    OK. If you don´t need to store the file the client computer you can call the save/load scripts from director.

                    The save script must receive the data using GET or POST methods. Then store it in a file. A basic approach would be:

                    save.php:
                    <?php
                    //open the file at the end.
                    $myFile = fopen("/data.txt", "a+");
                    //write the post var called "datos"
                    fwrite($myFile, $_POST['datos']);
                    //close the file
                    fclose($myFile);
                    ?>
                    the problem is that you cant access from two places simultaneusly because you will get a file access error.

                    In director, when you want so save a data just call

                    on saveData me
                    --the data that I want to save.
                    tData = ["datos":"asdfasdf!"]
                    --call PHP script.
                    postNetText("www.mysite.com/save.php",tData)
                    end saveData

                    This is the most elemental piece of code.

                    For loading is a similar, try to google it, go to php.net an search for fread, fwrite, fopen, fclose to understand file handling methods.

                    good luck.


                    • 7. Re: save/load variables online
                      farazfo Level 1
                      thank you so muchhhh..... "ensamblador "
                      you helped me so much......
                      thank you for the .php code:D really perfect...
                      • 8. Re: save/load variables online
                        farazfo Level 1
                        how can I use a .cgi file instead of .php file?
                        whats the script of .cgi file?
                        • 9. Re: save/load variables online
                          ensamblador Level 1
                          Of course, you can use any server scripting, the basic idea is the same.

                          The source code is not a problem just sear for http://www.google.cl/search?q=cgi+file+handling&sourceid=navclient-ff&ie=UTF-8&rlz=1B3GGGL _esCL276CL277

                          you'll find a lot of step by step-detailed tutorials.

                          Everytime you want to know how to code a specific action in a specific language just sear for "language action" in google. Google knows where´s everything. Use it wisely.

                          • 10. Re: save/load variables online
                            farazfo Level 1
                            I did exacty what you said to do with the .php file
                            and uploaded both .dcr and .php file
                            but it does not work:(
                            this is theexacty what is in save.php file:
                            <?php
                            $myFile = fopen("data.txt", "a+");
                            fwrite($myFile, $_POST['datos']);
                            fclose($myFile);
                            ?>
                            and I wrote this scrip on an sprite:
                            on mouseUp me
                            tData = ["datos":"asdfasdf!"]
                            postNetText("save.php",tData)
                            end
                            I'v uploaded .dcr and .php and data.txt on my website in the same directory
                            but when I click on that sprite nothing happens!!
                            maybe thats because save.php file does not have the permission to open data.txt file
                            help me please!
                            • 11. save/load variables online
                              farazfo Level 1
                              help me pleaseeeeee
                              • 12. save/load variables online
                                ensamblador Level 1
                                sorry.

                                Lets try to track the error.

                                Lets see if you can call your php file, if you're running in a server you can call http://testserver/save.php directly from your browser.

                                When you access to this page, are you prompted to save to disk the file "save.php"?, if yes, there is a problem with the server.

                                If no, do you get a 404 error?, this means that the page doesn't exists.

                                if everything is ok, change the line
                                fwrite($myFile, $_POST['datos']);
                                for
                                fwrite($myFile, $_GET['datos']);

                                and call directly from your browser:
                                http://testserver/save.php?datos=testingdata

                                if all with the server is OK, you will se a file created called data.txt containing "testingdata" in the same folder of php.

                                Luck!
                                • 13. Re: save/load variables online
                                  Level 7
                                  Although it won't write your server-side scripts for you, you might find this
                                  site helps you understand the processes involved.

                                  http://www.shocknet.org.uk

                                  There is example code in several languages there.


                                  --
                                  Mark A. Boyd
                                  Keep-On-Learnin' :)
                                  • 14. Re: save/load variables online
                                    farazfo Level 1
                                    thank you for your great help
                                    that was the error :D https://
                                    helped so much