3.
Select Control > Test Movie to test the document.
If the file successfully loads, the
the value of
dayNames
to
and the Output panel displays the text
false
Using variables in a project
When you build animations or applications with Flash, there are very few situations in which
you don't need to use any kind of variable in your project. For example, if you build a login
system, you might need variables to determine whether the user name and password are valid,
or whether they are filled in at all.
You can find more information on loading variables (such as name/value pairs) in
"Working with External Data," on page
In the following example, you use variables to store the path of an image you are loading with
the Loader class, a variable for the instance of the Loader class, and a couple of functions that
are called depending on whether the file is successfully loaded or not.
To use variables in a project:
1.
Create a new Flash document, and save it as imgloader.fla.
2.
Select Frame 1 of the Timeline, and add the following ActionScript to the Actions panel:
/* Specify default image in case there wasn't a value passed using
FlashVars. */
var imgUrl:String = "http://www.helpexamples.com/flash/images/
image1.jpg";
if (_level0.imgURL != undefined) {
// If image was specified, overwrite default value.
imgUrl = _level0.imgURL;
}
this.createEmptyMovieClip("img_mc", 10);
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip):Void {
target_mc._x = (Stage.width - target_mc._width) / 2;
target_mc._y = (Stage.height - target_mc._height) / 2;
}
mclListener.onLoadError = function(target_mc:MovieClip):Void {
target_mc.createTextField("error_txt", 1, 0, 0, 100, 20);
target_mc.error_txt.autoSize = "left";
target_mc.error_txt.text = "Error downloading specified image;\n\t" +
target_mc._url;
}
var myMCL:MovieClipLoader = new MovieClipLoader();
myMCL.addListener(mclListener);
myMCL.loadClip(imgUrl, img_mc);
106
Data and Data Types
event is called and the Output panel displays
complete
. If the text file cannot be downloaded, the
633.
success
.
Error
argument is set
Chapter 16,
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