Using FlashVars to pass variables to a SWF
Introduction
The FlashVars property of Macromedia Flash Player provides an efficient method of importing variables into the top level of a movie when first instantiated. This feature requires Flash Player 6 (or later). For information on passing variables with earlier versions, refer to Additional Information below.
FlashVars
Placed within the Object (ActiveX) or Embed Tag (Netscape and Macintosh Internet Explorer), the property "FlashVars" can be used to import root level variables to the movie. All variables are created before the first frame of the SWF is played. The format of the string is a set of name=value combinations separated by '&'. Special and/or non-printable characters can be escaped with a '%' followed by a 2 digit hexadecimal value. A single blank space can be represented using the '+' sign. For more information about URL encoding, please check URL Encoding: Reading special characters from a text file (TechNote tn_14143).
All browsers will support string sizes of up to 64KB (65535 bytes) in length. FlashVars must be assigned in both the OBJECT and EMBED tags in order to work on all browsers.
Object Tag Example:
<PARAM NAME=FlashVars VALUE="foo=Hello%20Worldgraph=first+line%0Dsecond+line">
Embed Tag Example:
<EMBED href="display.swf" FlashVars="foo=Hello%20Worldgraph=first+line%0Dsecond+line" ... (other parameters)></EMBED>
Encoding of this string is the same as the page containing it. Internet Explorer is responsible for providing UTF-16 compliant string on a Windows platform. Likewise, Netscape will provide a UTF-8 encoded string to the player.
Additional Information
Without FlashVars, variables can be passed to a SWF through HTML tags by appending them to URL of the SWF on a query string. For a simple example, refer to Different approaches to setting variables in a Flash movie (TechNote tn_14253). This method can present a problem if you need the variables immediately, because the SWF must be downloaded and played before large amounts of data can be requested from the server.
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!