Using FlashVars in an application
Using FlashVars to pass variables into Flash is similar to passing variables along the URL in
the HTML code. With FlashVars, instead of passing variables after the filename, variables are
passed in a separate
param
To use FlashVars in a document:
1.
Create a new Flash document, and name it myflashvars.fla.
2.
Select File > Publish Settings and make sure that HTML is selected, and then click OK to
close the dialog box.
3.
Add the following ActionScript to Frame 1 of the main Timeline:
this.createTextField("myTxt", 100, 0, 0, 100, 20);
myTxt.autoSize = "left";
if (_level0.myURL == undefined) {
myTxt.text = "myURL is not defined";
} else {
myTxt.text = _level0.myURL;
}
By default, HTML code publishes to the same location as myflashvars.fla.
4.
Select File > Publish to publish the SWF and HTML files.
5.
Open the directory containing the published files (where you saved myflashvars.fla on your
hard drive) and open the HTML document (myflashvars.html by default) in an HTML
editor such as Dreamweaver or Notepad.
6.
Add the code that appears in bold below, so your HTML document matches the following:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/
swflash.cab#version=8,0,0,0" width="550" height="400" id="myflashvars"
align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="myflashvars.swf" />
<param name="FlashVars" value="myURL=http://weblogs.macromedia.com/">
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="myflashvars.swf" FlashVars="myURL=http://
weblogs.macromedia.com/" quality="high" bgcolor="#ffffff" width="550"
height="400" name="myflashvars" align="middle"
allowScriptAccess="sameDomain" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
104
Data and Data Types
tag as well as in the
embed
tag.
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?