There are many reasons why you may want to send and load values from and to your Flash movies. Here is a brief list of some of the possibilities:
Send form values to a server-side script to store in a database
Send values from an email form to a server-side script to send the email
Load values from a text file (appropriate when the values are subject to change, such as for the current weather or for a links page)
Load values from a server-side script where the values are drawn from a database, such as categories in an e-commerce application
Send values to a server-side script for processing, and return a value to the Flash movie, such as for a login process
When you are loading variables into Flash, it is important that you correctly format the values to load. Flash can interpret data in URL-encoded format. URL-encoded variables follow these rules:
Each variable name is associated with a value using an equals sign, without spaces on either side of the equals sign.
Values loaded into Flash movies are always treated as strings; therefore, you should not enclose any values in quotes, as you would within ActionScript. A proper example of this is artist=Picasso.
When there is more than one name/value pair, each pair is separated by an ampersand. For example, artist=Picasso&type=painting.
Spaces within the values should be replaced by plus signs, not %20, as in: title=The+Old+Guitarist. (Spaces and %20 may also work, but stick with plus signs for the greatest compatibility.)
Any character that is not a digit, a Latin 1 letter (non-accented), or a space should be converted to the hexadecimal escape sequence. For example, the value "L'Atelier" should be encoded as L%27Atelier (%27 is the escape sequence for an apostrophe).
Here is an example of variables in URL-encoded format:
artist=Picasso&type=painting&title=Guernica&seller=Joey+Lott&room=L%27Atelier
Flash 6 introduced the LoadVars class, which provides a much more robust means of sending and loading variables than the loadVariables( ) method, which was available previously. Therefore, LoadVars is the preferred means of performing these actions, and it is used for the recipes in this chapter. Refer to Recipe 11.13, Recipe 11.17, and Recipe 11.19, which demonstrate how to transmit data associated with a form. There are, of course, other ways to send and receive data in Flash. Chapter 19 covers data transmission using XML. Chapter 20 covers data transmission using Flash Remoting (see also Chapter 21 with regard to recordsets).
Loading values using a LoadVars object is subject to Flash's standard security sandbox. That is, you can load variables from a text file or script only if it is within the same domain as the Flash movie. For ways around the domain security limitation, see Recipe 17.4, Recipe 15.2, and Recipe 15.6.