Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Data and Data Types > About variables > About loading variables > 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 tag as well as in the embed tag.
To use FlashVars in a document:
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;
}
|
NOTE |
By default, HTML code publishes to the same location as myflashvars.fla. |
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.adobe.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.adobe.com/"><param name="quality" value="high" /> <param name="bgcolor" value="#ffffff" /> <embed src="myflashvars.swf"FlashVars="myURL=http://weblogs.adobe.com/"quality="high" bgcolor="#ffffff" width="550" height="400" name="myflashvars" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" /> </object>
This code passes a single variable called myURL, which contains the string http://weblogs.macromedia.com. When the SWF file loads, a property named myURL is created in the _level0 scope. One of the advantages of using FlashVars or passing variables along the URL is that the variables are immediately available in Flash when the SWF file loads. This means you don't have to write any functions to check if the variables have finished loading, which you would need to do if you loaded variables using LoadVars or XML.
The text http://weblogs.macromedia.com, a variable in the HTML file, appears in the SWF file.
|
NOTE |
All browsers will support string sizes as large as 64K (65,535 bytes) in length. FlashVars must be assigned in both the |
|
|
|
|