4 Replies Latest reply on Oct 15, 2010 5:59 AM by Graham vdR

    How to read from and write to remote data file?

    Graham vdR Level 1

      Hi there

       

      I have two variables that I would like to store in a remote data file which can be accessed by my Flash file. It is for a voting system, so the first variable would be a counter that is incremented each time a user votes, and the second would be the total rating. The average rating would then be calculated from these.

       

      How would one store, retrieve, and then update these variables from the data file?

       

      I can create the system within a single Flash file for a single session, but obviously I'd like multiple users opening the file simultaneously to be able to access the data and update it.

       

      I'm using AS2 in CS3. Any help would be appreciated.

        • 1. Re: How to read from and write to remote data file?
          Ganesh_Palwe Level 3

          There are different mechanisms for communications between Flash and a database.

          One of the way is - Use LoadVars instances to send and receive data from serverside scripts (PHP, eg) that retrieve and save data to the database. Data may be sent via GET or POST, and is returned with var=value formatting.

          1 person found this helpful
          • 2. Re: How to read from and write to remote data file?
            Graham vdR Level 1

            Maybe I'm in over my head. I was hoping I could have a single .txt file sitting on the server which would contain the variables.

             

            From my look through the help files it looks like I'd be able to load the variables from here with no problem using URL encoding like this:

             

            &variable1=10&variable2=35

             

            But is there a way to write back to this text file to update the variables from Flash without needing any scripting on the server?

             

            I don't have any experience in any scripting other than ActionScript, and I'm still quite new with that.

             

            Thanks

            • 3. Re: How to read from and write to remote data file?
              Ganesh_Palwe Level 3

              I afraid not.

              But if you can use AS3 then you can make use of SharedObject class and make use of remote shared objects, details here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject. html

              Please note you will need Adobe Flash Media Server for using remote shared objects.

              • 4. Re: How to read from and write to remote data file? Help with php.
                Graham vdR Level 1

                Right, I've made significant progress since I started this topic. I now have my Flash and php files set up, and the communication between them is working. I'm having difficulty now retaining my variables in the php and updating them for the next session. The script that I have is as follows:

                 

                <?

                 

                $totalRating1 += $_POST['latestRating1'];
                $ratingCount1 ++;
                $averageRating1 = $totalRating1 / $ratingCount1;
                echo "&averageRating=$averageRating1";

                 

                ?>

                 

                The first line receives the variable "latestRating1" from the SWF. The new average rating is calculated and returned to the SWF as "averageRating". When I run it, however, the variables are reset each time. The average rating is always the same as the latest rating. How can I retain the variables so that they are updated and available for the next user?

                 

                Any advice would be appreciated. I am very new to php, and don't have any experience with other scripting languages. I'm using ActionScript2.