130 Tutorial: Building Your First Flash Application
A
for
loop is a block of code surrounded by a set of braces { } that repeats
for each increment of the
i
variable. In this case,
i
increments from 0 to 4
because the value of
totalImages
is 4. The
loadMovie()
method can be
used to load a Flash file or an image file into the movie clip. In this case it is
loading the external JPG files.
The next line of code loads the first image, stored in the
image0uri
variable, into the
holder4
movie clip instance, as follows:
slideShow_mc.slides_mc["holder4"].loadMovie(this["image0uri"
],slideShow_mc.slides_mc.getNextHighestDepth());
The following lines of code implement the functionality of the Next
button:
function nextMenuItem(eventObj:Object) {
slideShow_mc.gotoAndPlay("slide"+(currImage));
if ((cu1)>=totalImages) {
currImage = 0;
} else {
cu+;
}
menu_mc.title_txt.text =
this._parent["image"+cu"title"];
menu_mc.description_txt.text =
this._parent["image"+cu"desc"];
}
The code for the Next button is contained in the
nextMenuItem
function.
A function is a block of code that is set up to execute when a particular
event occurs. In this case, the function will run whenever the user releases
the mouse button over the Next button on the Stage.
Inside the function is the
gotoAndPlay()
method, which directs the
playhead to jump to a specific frame label in the Timeline. The Frame label
specified in this case is constructed from the word
slide
and the current
value of the
currImage
variable.
The next line contains an
if
statement that checks to see if the value of the
currImage
variable plus 1 is equal to the value of the
totalImages
variable. If this is true, the code sets the value of
currImage
to 0, otherwise
the code increments the value of
currImage
by 1.
The last two lines in the function set the text of the title and description
text boxes to the strings stored in the
image*title
and
image*desc
variables that correspond to the value of the
currImage
variable.
000_Getting_Started.book Page 130 Friday, September 2, 2005 12:22 PM
Summary of Contents for FLASH 8-GETTING STARTED WITH FLASH
Page 1: ...Getting Started with Flash...
Page 26: ...26 Introduction...
Page 94: ...94 Flash Basics...
Page 152: ...152 Index...