Graphics Reference
In-Depth Information
_halfWidth = width/2;
_halfHeight = height/2;
}
}
Now that all the images are in their correct locations on the stage,
they
re ready for user interaction via the
imageClicked
method. The
first thing we need to do is assign the Loader (image) that was clicked
to the
_imageLoader
variable (notice how we keep reusing that
variable and then we clear it out when we
'
'
re finished with it). After
that, there
s a set of ternary operators that are determining how to
scale the image and where to place it. The first one assigns a value to
the
_targetScale
variable by testing against the current scale of the
image. If the current scale is 1 (100%), then the image needs to be
sized down to the value of
_thumbScale
.Ifitisn
'
t currently at a scale
of 1, then it needs to be and that is the value assigned to
_target
Scale
. The next two ternary operators are essentially the same as one
another except for the fact that one is assigning a value to
_targetX
and the other to
_targetY
. To do so, we test against the current scale
of the image again. Once again, if the scale is equal to 1, the image is
on its way back to thumbnail size and therefore needs to be on its
way back to its thumbnail position as well. So we
'
ll grab the appropri-
ate property (
x
or
y
) from the appropriate Point in
_pointVector
and
assign that value. On the other hand, the current scale may not be
equal to 1. If that
'
s the case, the image is on its way to being viewed
at full size and needs to be placed in the correct location. This is
where the
_halfWidth
and
_halfHeight
variables come in and allow
us to center the full-size image to the gallery itself:
'
_halfWidth - (_imageLoader.content.width/2)
Now, we have stored the values we need prior to the targeted
image being altered in any way, so let
s start altering it. The first
thingtodohereischecktoseeif
_targetScale
issetto1.Ifitis,
we know the image is about to be viewed, and we need to make
sure it
'
'
s in front of all other images in the gallery. To do that we
'
ll
use
swapChildren
with the image that sits at the top of the gallery
'
s
display list (
getChildAt(numChildren
-
1)
). After all that is finished, it
s
time to manipulate the target image by assigning our stored values
to set its scale and position. And finally, let
'
'
s clear that associated
memory up again by setting
_imageLoader
back to
null
.
private function imageClicked(e:MouseEvent):void {
_imageLoader = Loader(e.target);
_targetScale = _imageLoader.scaleX == 1 ? _thumbScale :
1;
_targetX = _imageLoader.scaleX == 1 ?
_pointVector[pointIndex(_imageLoader)].x : _halfWidth
-
(_imageLoader.content.width/2);