Chapter 18. Sending and Loading Variables

Introduction

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 ...

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.