You can use variables in different ways in a SWF file, depending on what you need the
variables for. For more information, see the following topics:
"Using variables from the URL" on page 101
"Using FlashVars in an application" on page 104
"Loading variables from a server" on page 105
Using variables from the URL
When you develop an application or simple example in Flash, you might want to pass values
from an HTML page into your Flash document. The passed values are sometimes known as
the query string, or URL-encoded variables. URL variables are useful if you want to create a
menu in Flash, for example. You can initialize the menu to show the correct navigation by
default. Or you can build an image viewer in Flash and define a default image to show on
the website.
To use URL variables in a document:
1.
Create a Flash document, and name it urlvariables.fla.
2.
Select File > Save As, and save the document on your desktop.
3.
Select Frame 1 of the Timeline, and add the following code in the Actions panel:
this.createTextField("myTxt", 100, 0, 0, 100, 20);
myTxt.autoSize = "left";
myTxt.text = _level0.myURL;
4.
Select Control > Test Movie to test the SWF file in Flash Player.
The text field displays
defined before you proceed, you need to check for the existence of the variables in Flash.
You can do this by checking to see if they are undefined.
5.
To check to see if the variable is defined, modify the ActionScript you added to the Actions
panel in step 3 to match the following code. Add the code that appears in bold:
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;
}
When you publish your Flash document, an HTML document is created by default in the
same directory as the SWF file. If an HTML file was not created, select File > Publish
settings, and make sure you select HTML in the Formats tab. Then publish your
document again.
. If you want to make sure the variables are properly
undefined
About variables
101
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?
Questions and answers