Open mailer.fla in Flash and double click the first frame to reveal the associated actions. You should see the following:

stop ();
function lineAdapt () {
 message_send = message;
 while (msg_count<length(message)) {
  msg_count = msg_count+1;
  if ((substring(message_send, msg_count, 2)) eq "
"
) {
   message_send = (substring(message_send, 1, msg_count-2))
   +"
"
+(substring(message_send, msg_count+2,
   (length(message_send))-msg_count+2));
  }
 }
 message = message_send;
 delete msg_count;
 delete message_send;
}

Note that some lines above have been spread across multiple lines for tutorial layout purposes.

Evaluation (Line by line):

  1. Stops the play head.
  2. Defines a custom function lineAdapt which will convert the flash carriage return marker ( " ") to the PHP equivalent (" "). This ensures that if the user types a comment with paragraph breaks, these breaks will be reflected in the email, rather than it being one very long line of text :o)
  3. Sets variable message_send to the value of message. This is a storage variable: we will adapt message_send rather than message because message is being displayed in a text box on screen and adapting it may cause strange visual output.
  4. Begins a loop which will continue until the newly created variable msg_count is greater than or equal to the length of the string contained in message.
  5. Incirments msg_count by 1.
  6. Conditional statement which checks if the 2 characters within the string message_send starting at letter number msg_count are equal to the string " ". If you type data into a text box in Flash and enter carriage returns, you wills see that the variable which stores that text fields value is adapted with a " " inserted where each carriage return should be, so we are looking for these markers using Line 6.
  7. If Line 6 returns True, replace the " " we just found with " " (which is the PHP equivalent of " "). This code looks complicated but it isn't really. Al it does it 'copies' the characters before and after the " ", the pastes those before, enters " " and pastes those after. The result is the equivalent string with " " instead of " ".
  8. Sets the variable message to the finalized version of message_send, which contains no " " markers. We do this because when we post our variables PHP will look for variables with the same name. Remember in the PHP code we refer to the variable messagenot message_send so we must make sure the correct variable holds the correct value.
  9. Deletes the counter variable for our loop from memory
  10. Deletes the temporary message_sendvariable we used for altering the new line markers.

Now if you examine the "Send" button you will see it has the following code:

on (release) {
 if (subject eq "" or message eq "" or from eq "") {
  stop ();
 } else {
  lineAdapt();
  loadVariablesNum ("mail.php3", 0, "POST");
  gotoAndStop (2);
 }
}

Evaluation (Line by line):

  1. Says "Perform these actions when this button is clicked then released"
  2. Checks to see if any variable has no value. We don't want people sending us mail with no reply address for instance.
  3. Line 2 returns True, stop.
  4. Line 2 returns False, go on.
  5. Perform the predefined function lineAdapt () on our currently entered variables.
  6. Send variables, using the POST method, to our PHP script which will send the email off. (Note that you could also use LoadVars objects in place of LoadVariables if you wish to make this more synchornous. See the LoadVariables and LoadVars tutorial.)
  7. Go to the confirmation message and stop once the email is sent.

Almost done now...