19.0.
Introduction
There are many reasons why you may want to send
and load values from and to your Flash movies, including to:
-
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 loading data from a URL, the Flash Player
interprets the data in one of three possible ways: as text, raw
binary data, or URL-encoded variables. 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.
-
Variable 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 ampersandfor 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). See Table 19-1 for a list
of common escape sequences.
Table 19-1. Common URL-encoded escape
sequences
Character |
Escape sequence |
Character |
Escape sequence |
<space>
|
%20 or + |
.
|
%2E |
!
|
%21 |
/
|
%2F |
"
|
%22 |
:
|
%3A
|
#
|
%23 |
;
|
%3B
|
$
|
%24 |
<
|
%3C
|
%
|
%25 |
=
|
%3D
|
&
|
%26 |
>
|
%3E
|
'
|
%27 |
?
|
%3F
|
(
|
%28 |
@
|
%40
|
)
|
%29 |
|
|
%7C
|
*
|
%2A |
~
|
%7E
|
+
|
%2B |
\
|
%5C
|
,
|
%2C |
^
|
%5E
|
-
|
%2D |
_
|
%5F
|
Here is an example of variables in URL-encoded
format:
artist=Picasso&type=painting&title=Guernica&room=L%27Atelier
Sending and loading data has changed
dramatically in ActionScript 3.0. The LoadVars class has
been removed and replaced with a more robust URLLoader class
in the flash.net package. URLLoader is supported by a
new cast of characters, namely URLRequest,
URLVariables, and URLStream (and a few others). These
classes combine to form a rich API that offers more functionality
and flexibility than what was available in previous versions.
Something that has not changed, however, is that
loading data into the Flash Player is still subject to the standard
security sandbox. That is, you can load from a file or script only
if it is within the same domain that the movie is served from. For
ways around the domain security limitation, see Recipe
3.12.
|