Graphics Programs Reference
In-Depth Information
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// set the viewer destination coordinates
viewer.dx = thisObj.x;
viewer.dy = thisObj.y;
viewer.dz = thisObj.z/2;
// prepare for zooming in on the flag
zoomIn = true;
// identify the flag number
mySelection = k;
// store its z-coordinate and depth
zdata[numberOfObjects] = zdata[mySelection-1]
myDepth = thisObj.getDepth();
thisObj.swapDepths(30000);
break; // break out of the loop
Step 6: Complete the script for zooming in
The onEnterFrame handler is where the actual work of zooming in takes place. There
is a fair amount of new code here, and everything between the lines
// move the viewer towards the selected flag
and
// zoom out when the background has been clicked
should be deleted and replaced with the script shown here.
We begin by moving the viewer towards the selected flag as before. We define vari-
ables diffx , diffy , and diffz , which are measures of the difference between the
destination and current positions of the viewer in the x-direction, y-direction, and
z-direction respectively (lines 144-146). A variable difft , which is a rough measure
of the total difference, is also defined (line 147). The first three variables are used to
move the viewer toward the flag and are the same as previously, just written differ-
ently (lines 149-151).
The variable difft is used to determine basically when the viewer has reached the
destination position. When this number is small enough, less than 6 in this case, and
if zoomIn has been set to true, then we will start to zoom in on the flag (line 155).
The process of zooming the flag is done in equal increments. Each time the frame is
entered, step is incremented by 1 (line 157). The z-coordinate of the flag is updated
 
Search WWH ::




Custom Search