2.6 Loading External Variables
While most variables are created directly inside Flash, it's also common to load variables from an external text file, server script, or web page. Loading external variables does not mean simply assigning a value from an external source to existing variables. Loading external variables actually creates new variables at runtime. The following entries in the ActionScript Language Reference explain various variable-loading techniques:
-
LoadVars
-
loadVariables( )
-
fscommand( )
Additionally, in some browsers, JavaScript can set a variable in Flash at runtime using the syntax:
movieObj
.SetVariable("/someClip:firstName", "Colin");
where
movieObj
is an object reference to the Flash movie embedded in the page. This technique works only in the following browsers:
-
Internet Explorer on Windows
-
Netscape 4 on Windows, Macintosh, and Linux
-
Netscape 6.2 with Flash Player 6.0.40.0 (or higher) on Windows, Macintosh, and Linux
For complete details, see:
-
http://www.moock.org/webdesign/flash/fscommand/
Similarly, an HTML document's
<OBJECT>
and
<EMBED>
tags can create variables in a Flash movie, when the movie initially loads, via the
FlashVars
parameter or a query string. Variables passed to a Flash movie via
FlashVars
or a query string must be URL-encoded according to the rules described in the
LoadVars
class in the
Language Reference
. The following code uses the
FlashVars
parameter to create the variables
authorName
and
bookName
with the values "Colin Moock" and "ASDG" on the main timeline of a movie called
main.swf
:
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"
WIDTH="550"
HEIGHT="400">
<PARAM NAME=movie VALUE="main.swf">
<PARAM NAME=FlashVars VALUE="authorName=Colin+Moock&bookName=ASDG">
<EMBED src="main.swf"
FlashVars="authorName=Colin+Moock&bookName=ASDG"
WIDTH="550"
HEIGHT="400"
TYPE="application/x-shockwave-flash"
PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
</EMBED>
</OBJECT>
The
FlashVars
parameter requires Flash Player 6 or later and can pass a maximum of 63 KB of data to Flash. To pass data from HTML to earlier Flash Players, append the parameters to the URL of the
.swf
filename, as shown in the following example. In this case, the data transfer limit depends on the web server.
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"
WIDTH="550"
HEIGHT="400">
<PARAM NAME=movie VALUE="main.swf?authorName=Colin+Moock">
<EMBED
src="main.swf?authorName=Colin+Moock"
WIDTH="550"
HEIGHT="400"
TYPE="application/x-shockwave-flash"
PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
</EMBED>
</OBJECT>
The passed variables are always created on the movie's main timeline. There is no direct way to set variables in a nested movie clip using
FlashVars
or a query string. See Appendix H for more details on the
<OBJECT>
and
<EMBED>
tags.
|