- Home
- Tutorials
- Flash
- Intermediate
- Loading, Editting and Saving Variables via Perl And Flash ActionScript

Joining the Perl (CGI) and Flash
Part II - Uploading your Perl script and changing Permissions
Upload
1) Upload the the files "UpdateVars.cgi" and "subparseform.lib" to your cgi-bin on your server. IMPORTANT: these must be uploaded in ASCII mode. They will Not work if you upload them in binary mode.
2) Upload your Flash swf and the text file "Ex2TextFile.txt" in Binary mode to any directory you want.
Changing the Permissions of the uploaded files on your server
You need to change the permissions of the files "UpdateVars.cgi" and "Ex2TextFile.txt". The easiest way to do this is by using telnet to log-on to your account. Their are other ways but this is the most basic - others may be easier but it would be impossible to explain them all (ask your host how to change permissions if you are having trouble with this). Once you have successfully entered your login name and password you will see the shell prompt. You must then use the CD (Change directory) command to get to your cgi-bin. You can then list all the files in that directory by typing in ls - this will list the files located in that directory. You can type in ls -l to list all the files plus their permissions in that directory. In most cases it will be something like this:
%cd public_html
%cd cgi-bin
%ls -l
total 2
-rwxr-xr-x 1 Jun 24 15:30 UpdateVars.cgi
-rw-rw-r-- 1 Jun 24 15:00 subparseform.lib
%
I don't want to go into all the details on setting the file permissions so I'll just tell you what you need to do for this script. You need to change the permissions to 755. You can do this with the following command.
%chmod 755 UpdateVars.cgi
You also need to change the permission of the text file "Ex2TextFile.txt". To do this follow the same procedure as above. Use the CD command to get to the directory where this file is located. Change the permissions to 777. This allows you to write over the file with a cgi script. You can use the following command.
%chmod 755 Ex2TextFile.txt
Part III - Setting up the Flash Movie to work on your server
Basic Theory and Necessary Changes for the Flash Movie
The first thing the Flash movie does is load the variables contained in the text file that you have already uploaded. In this example the actionscript for doing that is located in one of the first frames of the movie. Here is the example code:
loadVariablesNum ("http://www.snowvids.com/PerlTut/Ex2TextFile.txt?Ran="
+random(999), 0);
You will have to change this in the Fla (It's clearly marked when you open it up) to the url path where the text file is located on Your server. In the example movie this Frame ActionScript is located on frame number 10 in the first layer. After you have changed this in the example Fla you can run it on your server and it will load the default values in the text file into your movie. One not on the above ActionScript - Notice the ?Ran="+random(999) portion, this just adds a random number onto the end of the text file so that the browser loads a new file each time, ie it's not in the cache. The default values are shown below.
Title=Default Title&Contact=jfhill1@aol.com&About=About Default&
News=Default News&Products=Default Products&Link=http://www.snowvids.com
In the movie there are dynamic text fields with variable names corresponding to what you see in the text file. For example the text field named "Title" will have the value "Default Title" when you load the variables from the text file and so on. If this part is not working you don't have the url path set correctly. This part will work independent of the Perl Script.
Edit / Update Variable Values
There is a link from the example movie to this part of the movie. In most cases however you will not want everyone editing your movie. You can avoid this by either making it a secret spot within the movie, have this area password protected or make the Edit/Update part of the example into it's own movie - that only you know the path to. The last way is probably the best and easiest way.
The update/Edit area contains the same text fields with the same name as the 1st part, with the exception that they are now input fields instead of dynamic fields.
You only need one button to update/Edit the text file. This button contains the ActionScript
on (release) {
loadVariablesNum ("http://www.snowvids.com/cgi-bin/UpdateVars.cgi",
0, "POST");
Status = "Updating Variables - Please Wait till you see
the Update Success Message";
gotoAndPlay (35);
}
You need to change the url Path to the url path to "UpdateVars.cgi" on your server. This will execute the cgi file and update your text file. The Status variable is just something extra I put in to tell the user when the update process begines. The cgi file will pass back a variable to tell you when it's Complete.
Conclusion
That's it. There's really not that much to it. Just make sure you've got all your paths and permissions set correctly and the rest is already done. It's not as hard as it sounds. Just takes a couple hours getting familiar with it, then after that you'll be able to alter this example to accomplish almost anything. One more step in making your flash movie truly interactive and dynamic.
-Jeffrey F. Hill
www.snowvids.com

