Home > Articles > Web Development > Dreamweaver & Flash

  • Print
  • + Share This

Stage 2: ActionScripting - Making Flash Talk to CGI

The ActionScripting for this movie is actually fairly simple. You will be surprised at how easy it is to make Flash send variables to and receive variables from a CGI file. The main part of the coding is taken care of for you in the CGI file that is covered in the next section.

I am a little set in my ways when it comes to making Flash files. I always like to add two layers at the top of the timeline: the first one is called "labels" and the other is called "actions." This always helps me organize my files and it also helps explain what I am doing. So throughout this section, I will refer to the "labels" and "actions" layers. Use Figure 5 as a reference.

Figure 5 Final timeline.

Frame "Labels"

We will start with the "labels" layer since there are only two labels. Add the "send" and "thanks" labels to Frames 3 and 10, respectively. We will refer to these shortly.

Frame "Actions"

I tried to break the actions apart as much as possible so they are easy to understand. That is why you see a lot of them in Figure 5. The first frame contains the following script:

subject = _root.menu.currentvalue;
if (subject == "Information") {
  to = "Info@yourServer.net";
} else if (subject == "Other") {
  to = "Other@yourServer.net";
} else if (subject == "Site bugs") {
  to = "SiteBugs@yourServer.net";
}

The first part of the code sets the "subject" variable equal to _root.menu.currentvalue. This sets what the user has selected from the pull-down menu equal to the "subject" variable, which is what the CGI script takes and applies to the "subject" field of the email. After this first line, we have an if statement that checks to see what the user has selected from the pull-down menu and sets the "to" variable up so that the email gets directed to the correct person.

Frame 2

In Frame 2, we have a simple action that makes the movie go to Frame 1. This creates a loop so that the movie is constantly checking the "subject" variable to see if it has changed. The script for this frame looks like this:

gotoAndPlay (1);

Frame 3

Frame 3 contains the script that calls the server to get feedback from the script. This script contains a bogus site name. This is where you will need to enter your site's name.

loadVariablesNum ("http://www.yourServer.net/cgi-bin/mail1.cgi", 0);

Frame 6

Frame 6 is the next frame that contains a script. This frame contains two if statements that check to see if one of the two variables has returned from the CGI script:

if (sent == "true") {
  gotoAndPlay ("thanks");
}
if (sent == "null email") {
  gotoAndPlay (1);
  _root.please.play();
}

The first if statement sends the user to the "thanks" label we set up earlier in this section under frame "labels." The second if statement triggers two events: First, it sends the user to the first frame to fill in any fields not correctly filled in; second, it triggers the "Please" movie clip that we created earlier.

Frame 7

If the playback head reaches Frame 7, it must not have received the variables from the CGI script, so this action will send the playback head back to the "send" label:

gotoAndPlay ("send");

This causes a loop until the action from Frame 6 is satisfied and it sends the script to another section of the movie.

Frame 15

Frame 15 contains a basic Stop action that will stop the movie from looping back to the beginning.

"Send" Button

The following action is attached to the "send" button we created:

on (release) {
loadVariablesNum ("http://www.yourServer.net/cgi-bin/mail1.cgi", 0, "POST");
  gotoAndPlay ("send");
}

This script sends the variables from the text fields to the CGI script so that it can put together the email for the server to send out. This script also sends the movie to the "send" label. This part of the movie contains a loop that waits to hear if all the fields were correctly completed from the CGI script.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.