Graphics Programs Reference
In-Depth Information
The second type of user interaction is clicking on the background map. We'll use click-
ing on this as a way for the user to quickly zoom out. In line 113, we'll define a variable
zoomOut . It's specified as a Boolean variable, which means it can have only the values
true and false, and we will initially set it to false since we don't yet want to zoom out.
When we click on the map, we will set its value to true (line 114). The mechanics of the
zooming out will be done in the next section of the script.
112
113
114
115
/// click on the background to zoom out
var zoomOut:Boolean = false;
bg_mc.onRelease = function() { zoomOut = true; }
The third type of interaction, using the Up Arrow and Down Arrow keys to zoom the
viewer in and out, has been discussed in earlier exercises. The script for this is included
in the next section.
The final section of the script deals with controlling the movement of the viewer. We
begin by defining the variable step in line 119, whose purpose is to divide some of the
viewer movement into steps, as we will soon see. We will use an onEnterFrame handler,
as usual, to provide the motion.
The next part of the script controls the movement of the viewer towards the selected
flag. Rather than a constant, linear change of movement of the viewer, we will have a
nonlinear easing motion as shown in lines 123-125. Here is how it works. We first take
the difference between the destination coordinates and the current coordinates. The
difference is divided by the value of viewerSpeed and added to the current coordinates.
116
117
118
119
120
121
122
123
124
125
126
// --------------------------------------------------------
// create the viewer or object movement
var step:Number = 0; // step number for viewer movement
this.onEnterFrame = function()
{
// move viewer towards the selected flag
viewer.x += (viewer.dx - viewer.x)/viewerSpeed;
viewer.y += (viewer.dy - viewer.y)/viewerSpeed;
viewer.z += (viewer.dz - viewer.z)/viewerSpeed;
 
Search WWH ::




Custom Search