This code passes a single variable called
http://weblogs.macromedia.com
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.
7.
Save your changes to the HTML document, and then close it.
8.
Double click myflashvars.html to test the application.
The text
http://weblogs.macromedia.com
SWF file.
All browsers will support string sizes as large as 64K (65,535 bytes) in length.
FlashVars must be assigned in both the object and embed tags in order to work on
all browsers.
Loading variables from a server
There are several ways to load variables into Flash from external sources (such as text files,
XML documents, and so on). You can find much more information on loading variables,
including name/value pairs, in
In Flash, you can easily load variables using the LoadVars class, as shown in the next example.
To load variables from a server:
1.
Create a new Flash document.
2.
Select Frame 1 of the Timeline, and add the following ActionScript in the Actions panel:
var my_lv:LoadVars = new LoadVars();
my_lv.onLoad = function(success:Boolean):Void {
if (success) {
trace(this.dayNames); // Sunday,Monday,Tuesday,...
} else {
trace("Error");
}
}
my_lv.load("http://www.helpexamples.com/flash/params.txt");
This code loads a text file from a remote server and parses its name/value pairs.
Download or view the text file (http://www.helpexamples.com/flash/params.txt) in a
browser if you want to know how the variables are formatted.
, which contains the string
myURL
. When the SWF file loads, a property named
, a variable in the HTML file, appears in the
Chapter 16, "Working with External Data," on page
myURL
633.
About variables
105
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?