104
Data and Data Types
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:
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;
}
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>
NO
TE
By default, HTML code publishes to the same location as myflashvars.fla.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...