Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 374

Programming actionscript 3.0
Table of Contents

Advertisement

When you define variables within the URLVariables constructor or within the
URLVariables.decode()
ampersand (
) character because it has a special meaning and acts as a delimiter. For example,
&
when you pass an ampersand, you need to URL-encode the ampersand by changing it from
to
because the ampersand acts as a delimiter for parameters.
%26
Loading data from external documents
When you build dynamic applications with ActionScript 3.0, it's a good idea to load data
from external files or from server-side scripts. This lets you build dynamic applications
without having to edit or recompile your ActionScript files. For example, if you build a "tip of
the day" application, you can write a server-side script that retrieves a random tip from a
database and saves it to a text file once a day. Then your ActionScript application can load the
contents of a static text file instead of querying the database each time.
The following snippet creates a URLRequest and URLLoader object, which loads the
contents of an external text file, params.txt:
var request:URLRequest = new URLRequest("params.txt");
var loader:URLLoader = new URLLoader();
loader.load(request);
You can simplify the previous snippet to the following:
var loader:URLLoader = new URLLoader(new URLRequest("params.txt"));
By default, if you do not define a request method, Flash Player loads the content using the
HTTP
method. If you want to send the data using the
GET
property to
request.method
following code shows:
var request:URLRequest = new URLRequest("sendfeedback.cfm");
request.method = URLRequestMethod.POST;
The external document, params.txt, that is loaded at run time contains the following data:
monthNames=January,February,March,April,May,June,July,August,September,Octo
ber,November,December&dayNames=Sunday,Monday,Tuesday,Wednesday,Thursday,
Friday,Saturday
The file contains two parameters,
comma-separated list that is parsed as strings. You can split this list into an array using the
method.
String.split()
Avoid using reserved words or language constructs as variable names in external data
files, because doing so makes reading and debugging your code more difficult.
374
Networking and Communication
method, you need to make sure that you URL-encode the
using the static constant
POST
and
monthNames
method, you need to set the
POST
URLRequestMethod.POST
. Each parameter contains a
dayNames
&
, as the

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents