<classwork>

Server-side / Data Access

A Flash document can load data from an external source by using one of the following data loading calls:

XML.load(), XML.sendAndLoad(), LoadVars.load(), LoadVars.sendAndLoad(), loadVariables(), loadVariablesNum(), MovieClip.loadVariables(), XMLSocket.connect(), and Macromedia Flash Remoting (NetServices.createGatewayConnection).

Also, a SWF file can import runtime shared libraries (RSLs), or assets defined in another SWF file, at runtime. By default, the data or RSL must reside in the same domain as the SWF file that is loading that external data or media.

Loading External Variables

This is useful for recieving and sending information into your Flash file, such as names, dates, order information, quizes, etc.

Flash isn’t limited only to the variables that we build into it, nor to the variables that our user may input. Flash can import variables directly from a text file off of the web and can also send variables back to the web directly from the movie.

Movies can send variables to a URL by using the Get URL action. Any variable/value pairs that are declared on the active timeline will be sent along with the url, as long as the variable send method is defined (GET or POST). Get sends only a small number of variables, Post send more information.

This requires that the variables be in a special format called URL-encoded.

URL-encoded text requires that each variable travel in a pair with its associated value separated by the = symbol. Each pairing much be separated by an ampersand (&). Lastly, spaces are not permitted. So instead, the + symbol is used.

The variable that enter Flash should be put in Variable/Value pairs and separated by an ampersand symbol.

variable1=value1&variable2=value2&variable3=value3

They are then loaded into Flash with the following action:

loadVariablesNum() for levels
or
loadVariables() for loading into movie clips

The text file will have information which looks like this:
name=Simon&age=12&interests=soccer

This will be seperated out by Flash and can be used for your movie.

We can also load in variables with the loadVariables action.
It does the same thing as the get URL action and is used to load in
variable name/value pairs as well.

Example:

on (release) {
loadVariables ("mytext.txt", "mymovieclip");
}

this loads variables from the file mytext.txt into the movie clip,
"mymovieclip".

download the load variables sample file