EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 106

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
106 Data and Data Types
3. Select Control > Test Movie to test the document.
If the file successfully loads, the
complete event is called and the Output panel displays
the value of
dayNames. If the text file cannot be downloaded, the success argument is set
to
false and the Output panel displays the text Error.
Using variables in a project
When you build animations or applications with Flash, there are very few situations in which
you dont 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 Chapter 16,
“Working with External Data,” on page 633.
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);

Table of Contents

Related product manuals