Macromedia Flash: passing external parameters to a Flash (swf) movie
Explicit and by file
Flash 6.0 (MX) or later
The FlashVars parameter loaded with explicit vars passed as and URL encoded query string
It's an explicit parameter passed as a HTML tag in the <OBJECT> (IE) or <EMBED> (NS) declarations in the body of the HTML where the swf is inserted.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=4,0,0,0"
id="AlternaturaLogo001" width="640" height="100">
<param name="FlashVars" value="&Var1=1&Var2=2&Var3=3">
<param name="Movie" value="images/AlternaturaLogo001.swf">
<param name="Quality" value="High">

<embed name="AlternaturaLogo001" 
src="images/AlternaturaLogo001.swf" 
quality="high" 
width="640" height="100" 
FlashVars="&Var1=1&Var2=2&Var3=3"
type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi? P1_Prod_Version=ShockwaveFlash">

</object>

When we talk about passing vars to swf in URL encoded query string, we are talking about a format as the one you are seeing above

&<varName>=<VarValue>&<VarName>=<VarValue>&...

<varName> and <varValue> should be properly URL encoded, in VBScript for ASP you assure that by applying the Server.URLEncode method to the VarName and VarValue, to use the return values to build the string to return.

Later inside the swf, ActionScript can access this vars values by invoking _root.VarName to return the associated value.

 

The FlashVars parameter loaded with the reference to a file that can be later accessed by ActionScript to retrieve from it the target vars
A particular powerful Var to pass to the swf is a file name. This file can then be accessed from the swf through ActionScript (using the LoadVars() object). ActionScript expects to load from the file a string with a chain of variables name and value in a URL encoded query string fashion.
Comparison of the 2 methods
Passing explicit set of vars Passing a file to later load vars from it

In a static server with no dynamic technology (ASP, PHP, etc.)

This is the preferred method, since you can't elaborate variable set of of variables to pass the swf, so the values you will pass will be regularly fixed, and only change when you edit the HTML parameter FlashVars manually.

This usually will be the right solution.

If you chose this method is because you perhaps want to better organize your data in a txt file, so when you want to manually maintain the data, you edit a plain txt file, and not the HTML file.

And other possible advantage is that you don't expose in the directly in the HTML source of the page your data, and offer a workaround for potential gossipers to reach the source of your data.

This method has the con of demanding 2 calls to the serverto fully resolve the page to be displayed in the client:

  1. Load the HTML
  2. When the swf load, it has now to call the server again to load the file with the variables for the Flash movie.

Clearly in terms of server performance, and client downloading times, this is not a useful solution.

In a dynamic server with dynamic technology (ASP, PHP, etc.) that let you build dynamic variable files to pass to the swf 

As you have a dynamic server you can build the PARAM FlashVars value anything you want, in this case a variable URL encoded string.

Again the advantage is that you build the main HTML data with the variable set of FlashVars, in just a call to the server. 

In this case you not only can pass a fixed txt file with the parameters, but an asp or php file, with the variable swf vars information.

The con again is that you need two calls to the server, and in the case of a dynamic server, the overhead is greater, since two processes should be solved in the HTML preprocessor (ASP, PHP, etc).

But it can make easily to manage multiple swf queries stored in different dynamic pages, without touching the core of the code that produces the standard HTML for the insertion of the swf object.

Obviously, the info pass to the swf will be not directly exposed, and will demand and additional workaround to the gossiper. 

Accesing the passed vars form inside the swf using ActionScript
The external passed values are seen from ActionScript as properties of the _root object.

If the passed URL encoded string looks like 

&var1=Value1&Var2=Value2&...

you retrieve the value of Var1 or Var2 from ActionScript in the swf by

Value1 = _root.Var1
Value2 = _root.Var2

Accesing the vars pased in an external file
You have to declare a LoadVar() object

Dim loading = new LoadVars()

Then load into the object the external file

loading.load(FileName)

Note: here the swf will request the file from the server by itself, becoming the second request to the server in the loading of the same page.

After that each of the vars values declares in the string retrieved from the file will be accessible as properties of the loading object

If the file returns a string 

&var1=Value1&Var2=Value2&...

you retrieve the value of Var1 or Var2 from ActionScript in the swf by

Value1 = loading.Var1
Value2 = loading.Var2

Flash earlier versions
  No FlashVars parameter available, vars passed as appended query string to the swf file

It is always possible to pass parameters as a appended query string to the swf file name.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=4,0,0,0"
id="AlternaturaLogo001" width="640" height="100">
<param name="Movie" value="images/AlternaturaLogo001.swf?Var1=1&Var2=2&Var3=3">
<param name="Quality" value="High">

<embed name="AlternaturaLogo001" 
src="images/AlternaturaLogo001.swf?Var1=1&Var2=2&Var3=3" 
quality="high" 
width="640" height="100" 
type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi? P1_Prod_Version=ShockwaveFlash">

</object>

The access methods to this vars has not been tested, but it surely can be accessed as properties of the _root object.

Back to parent link