User Guide

122 Chapter 3: Using Best Practices
Collecting and formatting data
Applications depend on user interaction with the SWF file. Frequently, it depends on the user
entering data into forms, such as using combo boxes, buttons, text fields, sliders, and so on. You
might create custom input devices, use the UI Components included with Flash, or download
components. You might collect data in a series of pages (sometimes each one is a screen) that are
contained within the single SWF file, which the user submits to the server. Flash provides many
ways you can enter and format data in Flash applications. This flexibility exists because of the
capabilities you have with animation and creative control over the interface, and error checking
and validation you can perform using ActionScript.
There are several benefits to using Flash to build forms to collect data:
You have increased design control.
You have decreased or no need for page refreshing.
You can reuse common assets.
However, Flash might take longer to create your form than if you create it using HTML, which is
a drawback.
Tip: If you want to save information that you collect from the user, you can save it in a shared object
on the user’s computer. Shared objects let you store data on a user’s computer, which is similar to
using a cookie. For more information on Shared objects, see “SharedObject class” in Flash
ActionScript Language Reference.
Sending and processing data
The server sending data to and from Flash must be able to interpret the data that it receives. A
standard format is URL-encoded data that is saved in name/value pairs, as the following example
shows:
&name=slappy&score=398
A complication arises when the value being passed uses the special ampersand (&) character. In
this case, the value is terminated because the data is treated as though the previous value has been
terminated, as the following code shows:
&name=Mac&Tosh&score=136
If Flash loads these variables from an external site, the following variables would be defined:
score: 136
Tosh:
name: Mac
To get the code to work properly, you must encode the special characters in the URL (in this case,
the ampersand [&]):
&name=Mac%26Tosh&score=136
/* output:
score: 136
name: Mac&Tosh
*/