When you use SWF Flash files within websites and Web applications, you can pass variables into them from the Web page. You can also pass data between SWF files. To retrieve variables inside a Flash file, you need a small excerpt of ActionScript code. Flash files can therefore retrieve variables from the file URL, from the page HTML or JavaScript code, or from another Flash file. The process for retrieving variables inside a Flash file depends on where the variables are coming from.

Step 1

Pass the variables into the SWF. You can pass variables into Flash in a number of ways. Append a variable to the SWF filename when it is loaded into the Web page as follows:


Include the variable as part of an embed element in HTML as follows:


If you are passing variables from one Flash file to another, use the following ActionScript syntax:

var varConnection:LocalConnection = new LocalConnection(); varConnection.send("your_connection", "method_in_swf", "hello");

This would work where the SWF you are sending the variable to has a method named "method_in_swf" inside it.

Step 2

Retrieve variables in the target SWF. Open the target Flash file in Adobe Flash Professional. If the file does not already contain a layer for ActionScript code, create one now. Open the Actions panel. To retrieve variables either attached to the filename or passed as FlashVars, use the following:

var infoVar:String = root.loaderInfo.parameters["info"];

The parameters are stored as an array, so you can include a parameter name to retrieve its value, which in this case will be "hello." Alternatively, you can achieve this using the following slightly different syntax:

var infoVar:String = root.loaderInfo.parameters.info;

To retrieve variables sent using the LocalConnection class, include a parameter in the method you called. For example:

function method_in_swf(info:String){ //access the variable from the "info" parameter }

Step 3

Use the variable you retrieved. Once you have retrieved a variable inside a Flash file, you can use it as you would use a variable you defined in the file. For example, you may wish to write the variable out for display to the user or use it to determine how your SWF functions.