Graphics Reference
In-Depth Information
unchanged, will simply lay your unscaled images out in a vertical
line with 5 pixels between each one.
TIP
If you aren
t familiar with the Vector class, I would like to go ahead and
recommend that you take a few minutes to look it up in the Adobe
ActionScript 3.0 Language Reference online. The general description is
that a Vector is like an Array, but you only put one type of data in it. You
might have a Vector that contains Strings or one that contains Points as
we have in the SimpleGallery class. A Vector is more efficient to work
with than an Array.
'
Once the private variables have been set to match the
parameters, we
re going to run through a nested for loop and
call out to the createImage method if conditions permit. If
conditions permit? What do I mean by that? Well, you
'
ll notice
that I use the variables r and c in the for loops (yeah, yeah,
Iknow
'
variable names less than three letters). These represent
rows and columns, respectively, and we can use them to count
which image we
'
re currently on in our loop. For example, if
we
re
on image number 6 (2 + 4 = 6). However, if we only have five
images in our gallery, then we don
'
re on row 2 ( r=2 )andcolumn4( c=4 ), then we know we
'
twanttorunthe createImage
method, and we want to get out of the loop instead. If you
noticed and were wondering about the part of the code that says
columnLoop : prior to the for loop,thisiswhereitcomesin.By
placingthisbeforethe for loop, we
'
ve labeled the loop, and we
can reference it by that label from within itself or its nested
children loops ( break columnLoop ). So let
'
'
s look at this chunk of
code on its own, and while we
'
re at it, let
'
s take a quick look at
setPosition as well. We
ve seen this simple method in other
classes earlier in the chapter, and it does the same thing here. It
allows you to set the x and y positions of your newly instantiated
SimpleGallery.
'
public function
SimpleGallery(parent:DisplayObjectContainer,galleryPath:
String,imageArray:Array,columns:int=1,thumbScale:Number=1,
padding:Number=5) {
_galleryParent = parent;
_galleryPath = galleryPath;
_imageArray = imageArray;
_columns = columns;
_thumbScale = thumbScale;
_padding = padding;
_numberOfImages = imageArray.length;
Search WWH ::




Custom Search